Skip to content

Commit 4810100

Browse files
authored
Fixes #24233: Remove misleading JDK compatibility hint for TASTy errors (#25171)
Fix misleading JDK compatibility error message for TASTy version mismatches Fixes #24233 ### Description When the compiler encounters a TASTy version mismatch (e.g., attempting to read a TASTy file produced by a newer compiler version like 3.7.1 with compiler 3.3.6), it throws an `UnpickleException`. The error handling code in _`ClassfileParser`_ and `ClassfileTastyUUIDParser `was catching this as a generic `RuntimeException `and appending a misleading message suggesting to "check the JDK compatibility of your Scala version." ### This message was confusing because: The error is about TASTy format versions (majorVersion: 28), not Java classfile versions The JDK version suggestion is irrelevant to TASTy compatibility issues ### Changes Made - Modified exception handlers in `ClassfileParser.scala` and `ClassfileTastyUUIDParser.scala` - Added pattern matching to detect `UnpickleException `specifically - Suppress JDK compatibility hint for TASTy unpickling errors - Preserve the hint for actual classfile version issues ### Example **Before:** ``` class file ... is broken (version 52.0), please check the JDK compatibility of your Scala version (3.3.6), reading aborted with class dotty.tools.tasty.UnpickleException: TASTy signature has wrong version... ``` **After:** ``` class file ... is broken, reading aborted with class dotty.tools.tasty.UnpickleException: TASTy signature has wrong version... ``` The UnpickleException message already contains clear information about the TASTy version mismatch, making the JDK hint unnecessary and confusing. Testing - Manually verified code correctness through inspection - Changes are minimal and focused on error message formatting - No functional changes to compilation logic
1 parent 890b442 commit 4810100

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package classfile
55

66
import scala.language.unsafeNulls
77

8-
import dotty.tools.tasty.{ TastyReader, TastyHeaderUnpickler }
8+
import dotty.tools.tasty.{ TastyReader, TastyHeaderUnpickler, UnpickleException }
99

1010
import Contexts.*, Symbols.*, Types.*, Names.*, StdNames.*, NameOps.*, Scopes.*, Decorators.*
1111
import SymDenotations.*, unpickleScala2.Scala2Unpickler.*, Constants.*, Annotations.*, util.Spans.*
@@ -306,7 +306,9 @@ class ClassfileParser(
306306
catch {
307307
case e: RuntimeException =>
308308
if (ctx.debug) e.printStackTrace()
309-
val addendum = Header.Version.brokenVersionAddendum(classfileVersion)
309+
val addendum = e match
310+
case _: UnpickleException => ""
311+
case _ => Header.Version.brokenVersionAddendum(classfileVersion)
310312
throw new IOException(
311313
i""" class file ${classfile.canonicalPath} is broken$addendum,
312314
| reading aborted with ${e.getClass}:

compiler/src/dotty/tools/dotc/core/classfile/ClassfileTastyUUIDParser.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import dotty.tools.dotc.core.Symbols.*
1212
import dotty.tools.dotc.core.Types.*
1313
import dotty.tools.dotc.util.*
1414
import dotty.tools.io.AbstractFile
15-
import dotty.tools.tasty.TastyReader
15+
import dotty.tools.tasty.{ TastyReader, UnpickleException }
1616

1717
import ClassfileParser.Header
1818

@@ -37,7 +37,9 @@ class ClassfileTastyUUIDParser(classfile: AbstractFile)(ictx: Context) {
3737
catch {
3838
case e: RuntimeException =>
3939
if (ctx.debug) e.printStackTrace()
40-
val addendum = Header.Version.brokenVersionAddendum(classfileVersion)
40+
val addendum = e match
41+
case _: UnpickleException => ""
42+
case _ => Header.Version.brokenVersionAddendum(classfileVersion)
4143
throw new IOException(
4244
i""" class file ${classfile.canonicalPath} is broken$addendum,
4345
| reading aborted with ${e.getClass}:

0 commit comments

Comments
 (0)