Skip to content

Fix "signed byte" bug introduced in #234 #239

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

Merged
merged 1 commit into from
Feb 9, 2017

Conversation

Nadahar
Copy link
Contributor

@Nadahar Nadahar commented Feb 9, 2017

I made a serious error in e9daa3d. I must admit that I didn't know that Java defined byte as "signed" - to me that is such a strange concept that I've never even considered it. I've seen the negative "byte" values in the debugger, but I've assumed it was simply a display issue.

It seems short is the way to go when comparing "byte" values in Java, but I've kept it as a byte here since it's being put into a byte array after comparison. I've run regressions tests and there is no diff, as this code only makes a difference if a Huffman table entry has a xFF value - which I haven't seen yet.

@drewnoakes drewnoakes merged commit af8fa07 into drewnoakes:master Feb 9, 2017
@drewnoakes
Copy link
Owner

Java's lack of unsigned types is a real pain a library like this. Lots of widening takes place. Thankfully .NET has a much saner type system. Converting this library to .NET meant throwing out quite a bit of ugly code.

Some Java APIs use int when reading a byte from stream, where -1 means EOF. That makes comparisons like this one work.

BTW some IDEs (IntelliJ for example) will automatically flag errors such as this, as it can prove that the condition is never met.

@Nadahar
Copy link
Contributor Author

Nadahar commented Feb 9, 2017

@drewnoakes FindBugs found it for me, I simply must have forgotten to run it though FindBugs at the time. It does the same as e.g IntelliJ and point out that the condition can never be met.

Not having unsigned types is one thing (although bad enough), but actually naming the type byte while being signed is just wrong as I see it. I wonder how many bugs that decision has caused during Java's lifetime. If it was called anything with "int", (small, short, tiny etc) you'd expect it, but to me a byte is a collection of bits where the concept of sign "doesn't exist".

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.

2 participants