2

We are using Flatbuffer with Java bindings. The application is running Netty4 and has following code for handling Netty request:

String id;
try {
        request = PostRequest.getRootAsPostRequest(msg.getPayloadBuffer().nioBuffer());
        id = request.id(); // string

    } catch (final Exception exception) {
        ctx.writeResponseAndFlush(StatusCode.StatusCode400, exception);
        return;
    } finally {
        msg.getPayloadBuffer().release();
    }

traceId = request.traceId(); // <-- this string sometimes becomes null

This code occasionally sets traceId as null and I am not able to fully understand why. Is it because the underlying buffer might have been release and reused as I am releasing it in finally block?

Even then, why does it happen only rarely and not always?

Saurav Prakash
  • 1,880
  • 1
  • 13
  • 24
  • I think you've answered your own question, but yes, during the call to `traceId` the underlying buffer must still contain the full FlatBuffer. – Aardappel May 13 '22 at 02:17
  • Yeah i think i can see this, but I dont' understand why it happens only rarely and not always? – Saurav Prakash May 13 '22 at 17:28
  • Could you please share the reason behind why you use `final` keyword over `Exception` reference? Further, using still try-catch is really ill-formated-way of catching exception instead of preferring `try-with-resource` – Soner from The Ottoman Empire May 13 '22 at 17:50
  • @SauravPrakash Could you please share the reason behind why you use final keyword over Exception reference? Further, using still try-catch is really ill-formated-way of catching exception instead of preferring try-with-resource – Soner from The Ottoman Empire May 14 '22 at 12:33
  • Hi @snr, this is a code representation that I cam up with just to ask the question. – Saurav Prakash May 14 '22 at 21:29

0 Answers0