Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException: software.amazon.awscdk.services.lambda.LambdaRuntime cannot be cast to software.amazon.awscdk.services.lambda.InlinableJavascriptLambdaRuntime #504

Closed
eranation opened this issue Aug 3, 2018 · 1 comment · Fixed by #505

Comments

@eranation
Copy link

I was trying to create a new Lambda construct, it compiles well but when running cdk synth I'm getting this error:


Exception in thread "main" java.lang.ExceptionInInitializerError
        at ...MyStack.<init>(MyStack.java:25)
        at ..MyApp.<init>(MyApp.java:11)
        at ..MyApp.main(MyApp.java:15)
Caused by: java.lang.ClassCastException: software.amazon.awscdk.services.lambda.LambdaRuntime cannot be cast to software.amazon.awscdk.services.lambda.InlinableJavascriptLambdaRuntime
        at software.amazon.awscdk.services.lambda.LambdaRuntime.<clinit>(LambdaRuntime.java:11)
        ... 3 more

The code is simply


    Lambda lambda = new Lambda("MyLambda",
        LambdaProps.builder()
            .withCode(LambdaCode.file(...))
            .withHandler(...).withRuntime(LambdaRuntime.JAVA8)
            .build()
eladb pushed a commit that referenced this issue Aug 3, 2018
TypeScript uses inference to determine if a cast to an interface is legal but
strongly-typed languages like Java require that the down-casted class will
explicitly implement the interface.

The JavaRuntime class has static members that are down-casted from JavaRuntime
to a set of interfaces, to allow strong-typing of properties for various Lambda
use cases. These down-casts fail in e.g. Java because JavaRuntime doesn't implement
these interfaces explicitly.

We should add a compile-time check in jsii for such a use case.

Fixes #504
@eladb
Copy link
Contributor

eladb commented Aug 3, 2018

Fix in #505

@eladb eladb closed this as completed in #505 Aug 6, 2018
eladb pushed a commit that referenced this issue Aug 6, 2018
…#505)

TypeScript uses inference to determine if a cast to an interface is legal but
strongly-typed languages like Java require that the down-casted class will
explicitly implement the interface.

The JavaRuntime class has static members that are down-casted from JavaRuntime
to a set of interfaces, to allow strong-typing of properties for various Lambda
use cases. These down-casts fail in e.g. Java because JavaRuntime doesn't implement
these interfaces explicitly.

We should add a compile-time check in jsii for such a use case.

Fixes #504
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants