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

byte is a signed type in java, so we need to mask it with &0xFF #66

Merged
merged 1 commit into from
May 11, 2014

Conversation

andre77
Copy link

@andre77 andre77 commented May 10, 2014

for more details, see
http://stackoverflow.com/questions/11380062/what-does-value-0xff-do-in-java

pretty weird, that such a "bug" is still existing

the "int read()" method of NetInputStreamUDT should not return a negative value, since it is interpreted as an EOF
the java byte type can have values from -128 .. +127
so 50% of all byte values do convert to a negative integer, which results in an EOF Exception in some circumstances

for example if you use the readInt method of DataInputStream
http://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readInt()

the code looks like this:

public final int readInt() throws IOException {
        int ch1 = in.read();
        int ch2 = in.read();
        int ch3 = in.read();
        int ch4 = in.read();
        if ((ch1 | ch2 | ch3 | ch4) < 0)
            throw new EOFException();
        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
    }

the chance is pretty high to get an EOFException...
BTW: it took my a lot of time to find this one. But i do not want to complain :-)
the project is gorgeous, thanks a lot

@purthaler
Copy link

thumbs up

Andrei-Pozolotin pushed a commit that referenced this pull request May 11, 2014
byte is a signed type in java, so we need to mask it with &0xFF
@Andrei-Pozolotin Andrei-Pozolotin merged commit 760e96b into barchart:master May 11, 2014
@andre77
Copy link
Author

andre77 commented Jun 23, 2014

Hi,
is there a mvn repo with at least a SNAPSHOT version including this bug fix?

@tobyxdd
Copy link

tobyxdd commented May 14, 2016

exactly same scenario here 😂 took a whole night to find out

@tobyxdd
Copy link

tobyxdd commented May 14, 2016

seems I have to create a proxy class to fix this without building it by myself.

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

Successfully merging this pull request may close these issues.

4 participants