question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NPE unmarshalling an event

See original GitHub issue

I’m using Spring for REST and trying to unmarshall an event coming in with this code snippet:

@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Void> event(@RequestHeader Map<String, Object> headers,
            @RequestBody String body) {
        System.out.println("Receved request headers: " + headers);
        System.out.println("Received request body: " + body);
        if (MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(headers.get("content-type").toString())) {
            @SuppressWarnings("rawtypes")
            CloudEvent<AttributesImpl, Map> cloudEvent = Unmarshallers.binary(Map.class)
                .withHeaders(() -> headers)
                .withPayload(() -> body)
                .unmarshal();
            System.out.println("Received CloudEvent: " + cloudEvent);
            //...
        }
        return ResponseEntity.accepted().build();
    }

I get these headers and body:

Receved request headers: {host=****, user-agent=Go-http-client/1.1, content-length=40, accept-encoding=gzip, ce-id=81063005-d897-4162-8a79-5224bdde4d81, ce-source=/apis/v1/namespaces/default/cronjobsources/test-cronjob-source, ce-specversion=0.3, ce-time=2019-10-08T12:56:00.000398275Z, ce-type=dev.knative.cronjob.event, content-type=application/json, forwarded=for=172.30.252.225;proto=http, for=127.0.0.1, k-proxy-request=activator, x-b3-parentspanid=08fdcef844c5b6e6, x-b3-sampled=0, x-b3-spanid=7d2298100968d43e, x-b3-traceid=ff56838a09c39d245ad334a89c91a0c8, x-envoy-decorator-operation=javaspringknativecloudant-vwv5h-nlf5f.default.svc.cluster.local:80/*, x-forwarded-for=172.30.252.225, 127.0.0.1, 172.30.233.147, x-forwarded-proto=http, x-istio-attributes=ClsKF2Rlc3RpbmF0aW9uLnNlcnZpY2UudWlkEkASPmlzdGlvOi8vZGVmYXVsdC9zZXJ2aWNlcy9qYXZhc3ByaW5na25hdGl2ZWNsb3VkYW50LXZ3djVoLW5sZjVmCl0KGGRlc3RpbmF0aW9uLnNlcnZpY2UuaG9zdBJBEj9qYXZhc3ByaW5na25hdGl2ZWNsb3VkYW50LXZ3djVoLW5sZjVmLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwKQwoYZGVzdGluYXRpb24uc2VydmljZS5uYW1lEicSJWphdmFzcHJpbmdrbmF0aXZlY2xvdWRhbnQtdnd2NWgtbmxmNWYKKgodZGVzdGluYXRpb24uc2VydmljZS5uYW1lc3BhY2USCRIHZGVmYXVsdApHCgpzb3VyY2UudWlkEjkSN2t1YmVybmV0ZXM6Ly9hY3RpdmF0b3ItNzY1NDc1OTU0Ny00ZDd2bS5rbmF0aXZlLXNlcnZpbmc=, x-request-id=6041ed42-e2e0-46b5-b6eb-c5ff88120464}
Received request body: {"message":"Hello world! This is CRON!"}

And I get this NPE. Am I doing something wrong in my usage of the SDK?

java.lang.NullPointerException: null
	at sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(Unknown Source) ~[na:1.8.0]
	at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.<init>(Unknown Source) ~[na:1.8.0]
	at sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(Unknown Source) ~[na:1.8.0]
	at sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedType(Unknown Source) ~[na:1.8.0]
	at java.lang.reflect.Field.getAnnotatedType(Unknown Source) ~[na:1.8.0]
	at org.hibernate.validator.internal.metadata.provider.TypeAnnotationAwareMetaDataProvider.findTypeAnnotationConstraintsForMember(TypeAnnotationAwareMetaDataProvider.java:65) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findPropertyMetaData(AnnotationMetaDataProvider.java:244) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getFieldMetaData(AnnotationMetaDataProvider.java:227) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:137) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:125) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfigurationForHierarchy(AnnotationMetaDataProvider.java:108) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:203) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getOrCreateBeanMetaData(BeanMetaDataManager.java:231) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.metadata.BeanMetaDataManager.isConstrained(BeanMetaDataManager.java:174) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:195) ~[hibernate-validator-5.3.6.Final.jar!/:5.3.6.Final]
	at io.cloudevents.v02.CloudEventBuilder.build(CloudEventBuilder.java:183) ~[cloudevents-api-0.3.1.jar!/:na]
	at io.cloudevents.v02.CloudEventBuilder.of(CloudEventBuilder.java:158) ~[cloudevents-api-0.3.1.jar!/:na]
	at io.cloudevents.v02.CloudEventBuilder.build(CloudEventBuilder.java:164) ~[cloudevents-api-0.3.1.jar!/:na]
	at io.cloudevents.v02.http.Unmarshallers$$Lambda$22.00000000182159E0.build(Unknown Source) ~[na:na]
	at io.cloudevents.format.BinaryUnmarshaller$Builder.unmarshal(BinaryUnmarshaller.java:241) ~[cloudevents-api-0.3.1.jar!/:na]
	at application.rest.v1.Events.event(Events.java:75) ~[classes!/:1.0-SNAPSHOT]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gee4veecommented, Oct 10, 2019

So adding this to my pom fixed it. Thanks!

<hibernate-validator.version>6.0.17.Final</hibernate-validator.version>
0reactions
gee4veecommented, Oct 10, 2019

I see at com.google.gson.internal.ConstructorConstructor$3.construct(. We do not use gson.

Yes this seems to be related to a Java Cloudant Client issue. I will look into it separately, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help troubleshooting JAXB unmarshalling NPE - Stack Overflow
I am working with an API which I do not have control on, which returns XMLs. Basically I have directory object that can...
Read more >
NPE unmarshalling from StreamReader if startDocument isn't ...
XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:552) This exception occurs when the streamreader is already by the startdocument event.
Read more >
NullPointerException when unmarshalling with JAXB 1.0
I get the following error when unmarshalling with JAXB 1.0: Exception java.lang.NullPointerException - Profile2User(): null java.lang.
Read more >
javax.xml.bind.Unmarshaller.setAttachmentUnmarshaller java ...
@Override public Object unmarshal(Source source, @Nullable MimeContainer ... throw new UnmarshallingFailureException("NPE while unmarshalling: " + "This can ...
Read more >
Cisco Bug - Getting unmarshalling VMaxThinPoolDevice
Symptom: Inframgr log file contains NPE (Null pointer Exception) while collecting inventory for EMC VMax thin pool Conditions: If a VMAX ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found