From 32f93874aca8caf4a899d4f481365803d1fc46b6 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 19 Sep 2009 02:28:17 +0000 Subject: Working around a mysterious bug which was expos... Working around a mysterious bug which was exposed in r17461. --- src/library/scala/runtime/BoxesRunTime.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/library/scala/runtime/BoxesRunTime.java b/src/library/scala/runtime/BoxesRunTime.java index bd4ed42cd9..3f71bb9409 100644 --- a/src/library/scala/runtime/BoxesRunTime.java +++ b/src/library/scala/runtime/BoxesRunTime.java @@ -47,7 +47,20 @@ public class BoxesRunTime { } public static Character boxToCharacter(char c) { - return Character.valueOf(c); + // !!! Temporarily working around the "impossible" (?) fact that + // c can have a negative value here. In any revision since r17461 try: + // def foo = new (Short => Char) { def apply(x: Short) = x.toChar } + // foo(-100) + // and the -100 will get to Character, which will duly crash. + // The bug was masked before because the Characters were created + // with "new Character(c)" and the constructor avenue must have + // some check against negative values, whereas the static method doesn't. + // + // It appears to be Short-specific; I can't get anything similar + // out of Byte or Int. + return Character.valueOf((char)(c & 0xFFFF)); + // return new Character(c); <-- this also would work + // return Character.valueOf(c); <-- but not this } public static Byte boxToByte(byte b) { -- cgit v1.2.3