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

Calling toAlarmConfig on IMetric object causes JsiiException #3927

Closed
era878 opened this issue Sep 4, 2019 · 1 comment
Closed

Calling toAlarmConfig on IMetric object causes JsiiException #3927

era878 opened this issue Sep 4, 2019 · 1 comment
Assignees
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. language/java Related to Java bindings

Comments

@era878
Copy link

era878 commented Sep 4, 2019

On the latest CDK v1.6.1, the following code snippet in Java causes a JsiiException to be thrown when in previous version this has worked fine:

final MetricProps props = MetricProps.builder()
        .metricName("METRIC_NAME")
        .namespace("NAMESPACE")
        .statistic("Average")
        .period(Duration.seconds(300))
        .build();
final IMetric metric = new Metric(props);
metric.toAlarmConfig();

The actual output is:

Exception in thread "main" software.amazon.jsii.JsiiException: Unable to instantiate a new object for FQN
 @aws-cdk/aws-cloudwatch.MetricAlarmConfig: null
    at software.amazon.jsii.JsiiEngine.createNativeProxy(JsiiEngine.java:248)
    at software.amazon.jsii.JsiiEngine.nativeFromObjRef(JsiiEngine.java:133)
    at software.amazon.jsii.JsiiObjectMapper$JsiiDeserializer.deserialize(JsiiObjectMapper.java:140)
    at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3786)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2115)
    at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:2612)
    at software.amazon.jsii.JsiiObjectMapper.treeToValue(JsiiObjectMapper.java:55)
    at software.amazon.jsii.JsiiObject.jsiiCall(JsiiObject.java:60)
    at software.amazon.awscdk.services.cloudwatch.Metric.toAlarmConfig(Metric.java:64)
    at com.amazonaws.ec2nitrocanary.MyTest.main(MyTest.java:19)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at software.amazon.jsii.JsiiEngine.createNativeProxy(JsiiEngine.java:238)
    ... 9 more
Caused by: java.lang.IllegalArgumentException: No enum constant software.amazon.awscdk.services.cloudwatch
 .Statistic.undefined
    at java.lang.Enum.valueOf(Enum.java:238)
    at software.amazon.jsii.JsiiEngine.findEnumValue(JsiiEngine.java:272)
    at software.amazon.jsii.JsiiObjectMapper$JsiiDeserializer.deserialize(JsiiObjectMapper.java:137)
    at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3786)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2115)
    at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:2612)
    at software.amazon.jsii.JsiiObjectMapper.treeToValue(JsiiObjectMapper.java:55)
    at software.amazon.jsii.JsiiObject.jsiiGet(JsiiObject.java:111)
    at software.amazon.awscdk.services.cloudwatch.MetricAlarmConfig$Jsii$Proxy.<init>(MetricAlarmConfig
    .java:186)
    ... 14 more

The expected output is a valid AlarmConfig object.

@SomayaB SomayaB added bug This issue is a bug. language/java Related to Java bindings needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch labels Sep 6, 2019
@rix0rrr rix0rrr removed the needs-triage This issue or PR still needs to be triaged. label Sep 9, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 24, 2019

I believe this has been fixed in aws/jsii#754.

A recent CDK version should have the fix.

@rix0rrr rix0rrr closed this as completed Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. language/java Related to Java bindings
Projects
None yet
Development

No branches or pull requests

4 participants