Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 32cac0e

Browse files
committed
My workaround for the negative chars didn't work.
All bets are off in negative char land. This workaround "works" but there is still a negative value in the boxed char, which can come back out. This needs fixing...
1 parent f0dc32f commit 32cac0e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/library/scala/runtime/BoxesRunTime.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,19 @@ public static Character boxToCharacter(char c) {
6060
//
6161
// It appears to be Short-specific; I can't get anything similar
6262
// out of Byte or Int.
63-
return Character.valueOf((char)(c & 0xFFFF));
64-
// return new Character(c); <-- this also would work
65-
// return Character.valueOf(c); <-- but not this
63+
Character ret;
64+
65+
// straightforward workarounds like bitmasking do not seem to
66+
// work here; is java optimizing out "impossible" tests/ops? I
67+
// don't know, but this is the safe way:
68+
try {
69+
ret = Character.valueOf(c);
70+
}
71+
catch (ArrayIndexOutOfBoundsException e) {
72+
ret = new Character(c);
73+
}
74+
75+
return ret;
6676
}
6777

6878
public static Byte boxToByte(byte b) {

0 commit comments

Comments
 (0)