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

FSTObjectInput#read() violates the ObjectInput contract #56

Closed
rdicroce opened this issue Feb 27, 2015 · 2 comments
Closed

FSTObjectInput#read() violates the ObjectInput contract #56

rdicroce opened this issue Feb 27, 2015 · 2 comments

Comments

@rdicroce
Copy link

FSTObjectInput#read() currently does this:

return getCodec().readFByte();

Java sign extends the value when performing a widening conversion, from byte to int in this case, which means that read() is returning a signed int.

The Javadoc for ObjectInput#read() implies that the return value should be unsigned. It says the method should return "the byte read, or -1 if the end of the stream is reached". If the value were supposed to be signed, then -1 would be a valid value and could not be used as a sentinel.

So read() should do this instead, to make the value unsigned:

return getCodec().readFByte() & 0xFF;

@RuedigerMoeller
Copy link
Owner

Will checkback if the wrong behaviour is present for all codecs. Thanks for the report :-)

@RuedigerMoeller
Copy link
Owner

As I avoid use of streams in most IO code, stream handling/compliance/support in fst is not too well. The need to walk through significant length of code (wrapped streams) to just read a single byte is one reason why stock JDK serialization perfoms slow.
Fixed the issue, however it could be expected there are other issues regarding iostreams compliance.
Thx for reporting.

fixed with 2.24

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

No branches or pull requests

2 participants