diff options
author | Som Snytt <som.snytt@gmail.com> | 2016-09-07 22:00:14 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2016-10-20 22:13:54 -0700 |
commit | 3c5990ce5839f4bdfca8fed7f2c415a72f6a8bd8 (patch) | |
tree | f82b0265bcec314991b8c53d1ff4a9586734f7bf | |
parent | 9d3f0777ff883a7c59da3fa7fee156890f51701e (diff) | |
download | scala-3c5990ce5839f4bdfca8fed7f2c415a72f6a8bd8.tar.gz scala-3c5990ce5839f4bdfca8fed7f2c415a72f6a8bd8.tar.bz2 scala-3c5990ce5839f4bdfca8fed7f2c415a72f6a8bd8.zip |
SI-9915 Utf8_info are modified UTF8
Use DataInputStream.readUTF to read CONSTANT_Utf8_info.
This fixes reading embedded null char and supplementary chars.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 8 | ||||
-rw-r--r-- | test/files/run/t9915/C_1.java | 18 | ||||
-rw-r--r-- | test/files/run/t9915/Test_2.scala | 12 |
3 files changed, 36 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index f8c1a0d082..10e18eed00 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -8,7 +8,7 @@ package tools.nsc package symtab package classfile -import java.io.{File, IOException} +import java.io.{ByteArrayInputStream, DataInputStream, File, IOException} import java.lang.Integer.toHexString import scala.collection.{immutable, mutable} import scala.collection.mutable.{ArrayBuffer, ListBuffer} @@ -206,10 +206,14 @@ abstract class ClassfileParser { case name: Name => name case _ => val start = firstExpecting(index, CONSTANT_UTF8) - recordAtIndex(newTermName(in.buf, start + 2, in.getChar(start).toInt), index) + val len = in.getChar(start).toInt + recordAtIndex(TermName(fromMUTF8(in.buf, start, len + 2)), index) } ) + private def fromMUTF8(bytes: Array[Byte], offset: Int, len: Int): String = + new DataInputStream(new ByteArrayInputStream(bytes, offset, len)).readUTF + /** Return the name found at given index in the constant pool, with '/' replaced by '.'. */ def getExternalName(index: Int): Name = { if (index <= 0 || len <= index) diff --git a/test/files/run/t9915/C_1.java b/test/files/run/t9915/C_1.java new file mode 100644 index 0000000000..cbd52606be --- /dev/null +++ b/test/files/run/t9915/C_1.java @@ -0,0 +1,18 @@ + +public class C_1 { + public static final String NULLED = "X\000ABC"; + public static final String SUPPED = "𐒈𐒝𐒑𐒛𐒐𐒘𐒕𐒖"; + + public String nulled() { + return C_1.NULLED; + } + public String supped() { + return C_1.SUPPED; + } + public int nulledSize() { + return C_1.NULLED.length(); + } + public int suppedSize() { + return C_1.SUPPED.length(); + } +} diff --git a/test/files/run/t9915/Test_2.scala b/test/files/run/t9915/Test_2.scala new file mode 100644 index 0000000000..afed667cc6 --- /dev/null +++ b/test/files/run/t9915/Test_2.scala @@ -0,0 +1,12 @@ + +object Test extends App { + val c = new C_1 + assert(c.nulled == "X\u0000ABC") // "X\000ABC" + assert(c.supped == "𐒈𐒝𐒑𐒛𐒐𐒘𐒕𐒖") + + assert(C_1.NULLED == "X\u0000ABC") // "X\000ABC" + assert(C_1.SUPPED == "𐒈𐒝𐒑𐒛𐒐𐒘𐒕𐒖") + + assert(C_1.NULLED.size == "XYABC".size) + assert(C_1.SUPPED.codePointCount(0, C_1.SUPPED.length) == 8) +} |