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 FSTObjectInputNoShared #159

Open
vargusz opened this issue Oct 10, 2016 · 5 comments
Open

NullPointerException when using FSTObjectInputNoShared #159

vargusz opened this issue Oct 10, 2016 · 5 comments
Assignees

Comments

@vargusz
Copy link

vargusz commented Oct 10, 2016

The following code produces a NullPointerException in unshared mode:

List<URI> list = new ArrayList<>();
list.add(URI.create("about:blank"));

FSTConfiguration config = FSTConfiguration.createDefaultConfiguration();
config.setShareReferences(false);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
FSTObjectOutput output = new FSTObjectOutputNoShared(baos, config);
output.writeObject(list);
output.close();

byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
FSTObjectInput input = new FSTObjectInputNoShared(bais, config);
input.readObject();
input.close();

The stack trace is the following:

Exception in thread "main" java.io.IOException: java.lang.NullPointerException
    at org.nustaq.serialization.FSTObjectInput.readObject(FSTObjectInput.java:243)
Caused by: java.lang.NullPointerException
    at org.nustaq.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:353)
    at org.nustaq.serialization.FSTObjectInput.readObjectFields(FSTObjectInput.java:708)
    at org.nustaq.serialization.FSTObjectInputNoShared.instantiateAndReadNoSer(FSTObjectInputNoShared.java:94)
    at org.nustaq.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:370)
    at org.nustaq.serialization.FSTObjectInput.readObjectInternal(FSTObjectInput.java:327)
    at org.nustaq.serialization.serializers.FSTArrayListSerializer.instantiate(FSTArrayListSerializer.java:63)
    at org.nustaq.serialization.FSTObjectInput.instantiateAndReadWithSer(FSTObjectInput.java:497)
    at org.nustaq.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:366)
    at org.nustaq.serialization.FSTObjectInput.readObjectInternal(FSTObjectInput.java:327)
    at org.nustaq.serialization.FSTObjectInput.readObject(FSTObjectInput.java:307)
    at org.nustaq.serialization.FSTObjectInput.readObject(FSTObjectInput.java:241)

The issue has been around since fast-serialization 2.12, the code above works with 2.10 without the NullPointerException. The current version is 2.48.

@smigfu
Copy link

smigfu commented Dec 5, 2016

I am seeing the same problem with using an URI (w/o collection). A testcase is provided in #168. I didn't find any obvious yet in the code but I will keep on looking. It fails with shared and unshared references.

@smigfu
Copy link

smigfu commented Dec 5, 2016

I think the problem is that on deserializing the default "readObject" method isn' being called (as opposed to the "writeObject"). Thus in the URI class the required fields aren't being set (see the test case which has an internal class similar to what URI/URL are doing)

@RuedigerMoeller
Copy link
Owner

why not use default output stream ? the performance difference is kind of neglectable, in many cases its even faster ?

@vargusz
Copy link
Author

vargusz commented Apr 10, 2017

@RuedigerMoeller, I am in fact using the default config.getObjectOutput() stream now, the code in this bug report was only the result of some experimenting: I was playing around with replacing config.getObjectOutput() + output.getCopyOfWrittenBuffer() with something that doesn't create thread-local buffers, plus avoids creating both input and output streams on the same side like DefaultCoder does. But this is only a side note; this bug report was created to let you know that if you use FSTObjectInputNoShared in this specific way, you may get a NullPointerException.

@RuedigerMoeller
Copy link
Owner

thankx :) unshared mode is kind of untested currently (it worked sometime ago ..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants