Giter VIP home page Giter VIP logo

Comments (7)

spring-operator avatar spring-operator commented on May 1, 2024

Mark Fisher commented

I'm fixing this to avoid the NPE. However, it does look like you are calling getBodyContentAsString on the Message yourself? If that Message has no Content-Type header, then getBodyContentAsString() will return null (even after this fix). Can you describe what you would expect?

from spring-amqp.

spring-operator avatar spring-operator commented on May 1, 2024

Andrey Paramonov commented

My onMessage method is pretty simple:

public void onMessage(Message message) {
System.out.println("Received message: " + message);
}

getBodyContentAsString() is called from within toString() method.

Interestingly, although I send null BasicProperties, the messageProperties field in the received Message is not null, but all properties in this object are null:

#contentHeader<basic>(content-type=null, content-encoding=null, headers={}, delivery-mode=null, priority=null, correlation-id=null, reply-to=null, expiration=null, message-id=null, timestamp=null, type=null, user-id=null, app-id=null, cluster-id=null)

In that case I would expect that Message.toString() method return something like this:

Message(headers = {content-type=null, content-encoding=null, headers={}, delivery-mode=null, priority=null, correlation-id=null, reply-to=null, expiration=null, message-id=null, timestamp=null, type=null, user-id=null, app-id=null, cluster-id=null}, payload = {...})

from spring-amqp.

spring-operator avatar spring-operator commented on May 1, 2024

Mark Fisher commented

Okay. The recent commit should at least prevent the NPE. However, if the content-type header is indeed null, it would display a null body which is misleading. I think we need to create a separate issue (since this one is technically "fixed") for improving the toString() method on our Message class.

from spring-amqp.

spring-operator avatar spring-operator commented on May 1, 2024

Mark Fisher commented

I made another update. Now the toString() result of any non-null body will at least be called in the Message's own toString(). If you build from trunk, you should see output similar to what you described in the above comment.

from spring-amqp.

spring-operator avatar spring-operator commented on May 1, 2024

Andrey Paramonov commented

It did fix the original error, although now it's NPE in RabbitMessageProperties:

java.lang.NullPointerException
at org.springframework.amqp.rabbit.core.RabbitMessageProperties.getDeliveryMode(RabbitMessageProperties.java:308)
at org.springframework.amqp.core.Message.toString(Message.java:63)

from spring-amqp.

spring-operator avatar spring-operator commented on May 1, 2024

Mark Fisher commented

I added a null-check for deliveryMode, so that should no longer be a problem (on trunk).

from spring-amqp.

spring-operator avatar spring-operator commented on May 1, 2024

Andrey Paramonov commented

It works perfect now. Thank you Mark.

from spring-amqp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.