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

NullPointerException when using CfnApi::getBinaryMediaTypes from Java #4316

Closed
ivoanjo opened this issue Oct 1, 2019 · 2 comments · Fixed by #5103
Closed

NullPointerException when using CfnApi::getBinaryMediaTypes from Java #4316

ivoanjo opened this issue Oct 1, 2019 · 2 comments · Fixed by #5103
Assignees
Labels
bug This issue is a bug. language/java Related to Java bindings p1

Comments

@ivoanjo
Copy link
Contributor

ivoanjo commented Oct 1, 2019

Hello there! 👋

I've just run into an issue while trying to read the binaryMediaTypes for a SAM CfnApi. It looks like the Java generator does not properly handle when it gets a null for the underlying field.

Reproduction Steps

package com.myorg;

import software.amazon.awscdk.core.App;
import software.amazon.awscdk.services.sam.CfnApi;
import software.amazon.awscdk.services.sam.CfnApiProps;
import software.amazon.awscdk.core.Stack;
import java.util.Arrays;

public class HelloApp {
    public static void main(final String argv[]) {
        App app = new App();
        Stack stack = new Stack(app, "mystack", null);

        CfnApi cfnApi = new CfnApi(stack, "foo",
            CfnApiProps.builder().stageName("foo").build());

        cfnApi.getBinaryMediaTypes(); // <--- NullPointerException will happen inside here

        app.synth();
    }
}

What I expected: An empty collection returned from getBinaryMediaTypes() (I can live with a null too, it needed)

Error Log

java.lang.NullPointerException
    at java.util.Collections$UnmodifiableCollection.<init> (Collections.java:1026)
    at java.util.Collections$UnmodifiableList.<init> (Collections.java:1302)
    at java.util.Collections.unmodifiableList (Collections.java:1287)
    at software.amazon.awscdk.services.sam.CfnApi.getBinaryMediaTypes (CfnApi.java:195)
    at com.myorg.HelloApp.main (HelloApp.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282)
    at java.lang.Thread.run (Thread.java:748)

Environment

  • CLI Version : 1.10.0 (build 19ae072)
  • Framework Version: 1.10.0.DEVPREVIEW
  • OS : Ubuntu 16.04.6 LTS
  • Language : Java (JDK 8)

This is 🐛 Bug Report

@ivoanjo ivoanjo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 1, 2019
@SomayaB SomayaB added language/java Related to Java bindings @aws-cdk/aws-sam Related to AWS Serverless Application Model labels Oct 1, 2019
@SomayaB SomayaB added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 1, 2019
@RomainMuller
Copy link
Contributor

Yeah - looks like we need to check for null before we try to make a collection unmodifiable... This is a bug in the jsii runtime for Java.

@nija-at
Copy link
Contributor

nija-at commented Oct 2, 2019

This looks like a bug in our JSII Java bindings. Sending it @RomainMuller's way.

@nija-at nija-at assigned RomainMuller and unassigned nija-at Oct 2, 2019
@nija-at nija-at removed @aws-cdk/aws-sam Related to AWS Serverless Application Model needs-reproduction This issue needs reproduction. labels Oct 2, 2019
@RomainMuller RomainMuller added p0 p1 and removed p0 labels Nov 4, 2019
RomainMuller added a commit to aws/jsii that referenced this issue Nov 14, 2019
When a `null` value was returned fro an optional collection (List or
Map), it would be passed to the corresponding unmodifiable wrapper
(`java.util.Collections.unmodifiable~`), however these method are not
`null`-safe.

This makes the wrapping conditional to the collection not being `null`.

This addresses the cause of aws/aws-cdk#4316
mergify bot pushed a commit to aws/jsii that referenced this issue Nov 14, 2019
When a `null` value was returned fro an optional collection (List or
Map), it would be passed to the corresponding unmodifiable wrapper
(`java.util.Collections.unmodifiable~`), however these method are not
`null`-safe.

This makes the wrapping conditional to the collection not being `null`.

This addresses the cause of aws/aws-cdk#4316
eladb pushed a commit that referenced this issue Nov 19, 2019
Bug Fixes
- java: handle null-able collections correctly (#986) (e88e5e2), closes #4316
- jsii: unable to depend on modules with private declarations (#995) (08c4294), closes #994
- kernel: cannot pass decorated structs to kernel as "any" (#997) (2bd3183), closes #5066

Features
- jsii-config: introducing jsii-config (#981) (2bbf576), closes #904
- rosetta: extract and compile samples into "tablets" (#925) (eec44e1)
@mergify mergify bot closed this as completed in #5103 Nov 19, 2019
mergify bot pushed a commit that referenced this issue Nov 19, 2019
* feat: upgrade to jsii 0.20.7

Bug Fixes
- java: handle null-able collections correctly (#986) (e88e5e2), closes #4316
- jsii: unable to depend on modules with private declarations (#995) (08c4294), closes #994
- kernel: cannot pass decorated structs to kernel as "any" (#997) (2bd3183), closes #5066

Features
- jsii-config: introducing jsii-config (#981) (2bbf576), closes #904
- rosetta: extract and compile samples into "tablets" (#925) (eec44e1)

* fix broken code

* type a couple of more arrays

* fix another untyped array

* fix a couple more issues

* another untyped array

* more
eladb pushed a commit to cdklabs/decdk that referenced this issue Jan 18, 2022
* feat: upgrade to jsii 0.20.7

Bug Fixes
- java: handle null-able collections correctly (#986) (e88e5e2), closes aws/aws-cdk#4316
- jsii: unable to depend on modules with private declarations (#995) (08c4294), closes #994
- kernel: cannot pass decorated structs to kernel as "any" (#997) (2bd3183), closes aws/aws-cdk#5066

Features
- jsii-config: introducing jsii-config (#981) (2bbf576), closes #904
- rosetta: extract and compile samples into "tablets" (#925) (eec44e1)

* fix broken code

* type a couple of more arrays

* fix another untyped array

* fix a couple more issues

* another untyped array

* more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. language/java Related to Java bindings p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants