From 3c5990ce5839f4bdfca8fed7f2c415a72f6a8bd8 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 7 Sep 2016 22:00:14 -0700 Subject: SI-9915 Utf8_info are modified UTF8 Use DataInputStream.readUTF to read CONSTANT_Utf8_info. This fixes reading embedded null char and supplementary chars. --- .../scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/compiler/scala/tools/nsc/symtab') 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) -- cgit v1.2.3