In Java, I make the call:
String chunkSizeAsString = responseString.split(DOUBLE_NEW_LINE)[1]
.split(SINGLE_NEW_LINE)[0];
System.out.println("Trying to get integer value of '" + chunkSizeAsString + "'");
Integer chunkSize = Integer.valueOf(chunkSizeAsString, 16); // this is line 109
And get output:
Trying to get integer value of '8d'
Exception in thread "Thread-2" java.lang.NumberFormatException: For input string: "8d"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:481)
at java.lang.Integer.valueOf(Integer.java:556)
at ProxyWorker.handleRequest(ProxyWorker.java:109)
at ProxyWorker.run(ProxyWorker.java:41)
at java.lang.Thread.run(Thread.java:745)
So basically, I am calling Integer.valueOf("8d", 16)
and receiving a NumberFormatException
. I've seen lots of examples where the OP had forgotten to specify the correct radix, or the resulting number was outside the bounds of and Integer, Long, etc. But 0x8d = 141, which is comfortably within the bounds of an Integer.
So my question is, why is this happening, and how might I fix it?
N.B. As you can see, I am getting chunkSizeAsString
("8d") through a parsing monstrosity, and suspect there might be invisible characters involved. I have checked for "\u200e" and"\u200f" as mentioned here, and "\\p{C}" as mentioned here using the following addition above line 109:
chunkSizeAsString = chunkSizeAsString.replaceAll("\u200e", "");
chunkSizeAsString = chunkSizeAsString.replaceAll("\u200f", "");
chunkSizeAsString = chunkSizeAsString.replaceAll("[^\\p{Print}]", "");
But this has not changed the output.
Edit:
I am using jdk1.7.0_7, and the vendor is 'Oracle Corporation'. Thanks fge.
Edit 2: Updated jdk to 1.7u79 and realized I need to get the java vendor from the server where I am running and testing, not my home dev environment:
java version "1.7.0_79"
OpenJDK Runtime Environment (fedora-2.5.5.0.fc20-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
Edit 3: Following suggestions, I have done some sanity tests:
- Tests that check
Integer.valueOf("8d", 16)
andInteger.parseInt("8d", 16)
pass chunkSizeAsString.equals("8d")
is TruechunkSizeAsString.length()
= 2- integer values of the characters are 56 and 100, which are the ASCII codes for "8" and "d", all respectively