@@ -5,15 +5,16 @@ package classfile
5
5
6
6
import Contexts ._ , Symbols ._ , Types ._ , Names ._ , StdNames ._ , NameOps ._ , Scopes ._ , Decorators ._
7
7
import 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 }
10
10
import ast .tpd ._
11
- import java .io .{ ByteArrayInputStream , ByteArrayOutputStream , DataInputStream , File , IOException }
12
- import java . nio
11
+ import java .io .{ ByteArrayInputStream , ByteArrayOutputStream , DataInputStream , IOException }
12
+
13
13
import java .lang .Integer .toHexString
14
14
import java .net .URLClassLoader
15
+ import java .util .UUID
15
16
16
- import scala .collection .{ mutable , immutable }
17
+ import scala .collection .immutable
17
18
import scala .collection .mutable .{ ListBuffer , ArrayBuffer }
18
19
import scala .annotation .switch
19
20
import typer .Checking .checkNonCyclic
@@ -787,9 +788,7 @@ class ClassfileParser(
787
788
if (scan(tpnme.TASTYATTR )) {
788
789
val attrLen = in.nextInt
789
790
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
793
792
val tastyBytes : Array [Byte ] = classfile.underlyingSource match { // TODO: simplify when #3552 is fixed
794
793
case None =>
795
794
ctx.error(" Could not load TASTY from .tasty for virtual file " + classfile)
@@ -821,8 +820,11 @@ class ClassfileParser(
821
820
}
822
821
}
823
822
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). " )
826
828
return unpickleTASTY(tastyBytes)
827
829
}
828
830
}
0 commit comments