@@ -5,15 +5,16 @@ package classfile
55
66import Contexts ._ , Symbols ._ , Types ._ , Names ._ , StdNames ._ , NameOps ._ , Scopes ._ , Decorators ._
77import SymDenotations ._ , unpickleScala2 .Scala2Unpickler ._ , Constants ._ , Annotations ._ , util .Positions ._
8- import NameKinds .{ ModuleClassName , DefaultGetterName }
9- import dotty .tools .dotc .core .tasty .{TastyHeaderUnpickler , TastyPickler }
8+ import NameKinds .DefaultGetterName
9+ import dotty .tools .dotc .core .tasty .{TastyHeaderUnpickler , TastyReader }
1010import ast .tpd ._
11- import java .io .{ ByteArrayInputStream , ByteArrayOutputStream , DataInputStream , File , IOException }
12- import java . nio
11+ import java .io .{ ByteArrayInputStream , ByteArrayOutputStream , DataInputStream , IOException }
12+
1313import java .lang .Integer .toHexString
1414import java .net .URLClassLoader
15+ import java .util .UUID
1516
16- import scala .collection .{ mutable , immutable }
17+ import scala .collection .immutable
1718import scala .collection .mutable .{ ListBuffer , ArrayBuffer }
1819import scala .annotation .switch
1920import typer .Checking .checkNonCyclic
@@ -787,9 +788,7 @@ class ClassfileParser(
787788 if (scan(tpnme.TASTYATTR )) {
788789 val attrLen = in.nextInt
789790 val bytes = in.nextBytes(attrLen)
790- val headerUnpickler = new TastyHeaderUnpickler (bytes)
791- headerUnpickler.readHeader()
792- if (headerUnpickler.isAtEnd) { // A tasty attribute with that has only a header implies the existence of the .tasty file
791+ if (bytes.length == 16 ) { // A tasty attribute with that has only a UUID implies the existence of the .tasty file
793792 val tastyBytes : Array [Byte ] = classfile.underlyingSource match { // TODO: simplify when #3552 is fixed
794793 case None =>
795794 ctx.error(" Could not load TASTY from .tasty for virtual file " + classfile)
@@ -821,8 +820,11 @@ class ClassfileParser(
821820 }
822821 }
823822 if (tastyBytes.nonEmpty) {
824- if (! tastyBytes.startsWith(bytes))
825- ctx.error(" Header of TASTY file did not correspond to header in classfile. One of the files might be outdated or corrupted." )
823+ val reader = new TastyReader (bytes, 0 , 16 )
824+ val expectedUUID = new UUID (reader.readUncompressedLong(), reader.readUncompressedLong())
825+ val tastyUUID = new TastyHeaderUnpickler (tastyBytes).readHeader()
826+ if (expectedUUID != tastyUUID)
827+ ctx.error(s " Tasty UUID ( $tastyUUID) file did not correspond the tasty UUID declared in the classfile ( $expectedUUID). " )
826828 return unpickleTASTY(tastyBytes)
827829 }
828830 }
0 commit comments