Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler should provide better error messages when using unsupported JDK version #18573

Closed
WojciechMazur opened this issue Sep 19, 2023 · 4 comments · Fixed by #18618
Closed
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages compat:java itype:enhancement

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Sep 19, 2023

Latest release of JDK 21 might be a time when more and more people might want to migrate to latest Java version. However, if we'd try to do so, we might get a very nasty error.

Compiler version

3.3.0 (fixed in 3.3.1 for JDK 21, however the issue would still be present in future JDK's if more assumptions of classfile format are violated)

Minimized code

import java.nio.file.StandardOpenOption

@main def Test = {
  val x =  StandardOpenOption.CREATE
}

Output

>scalac main.scala
error while loading StandardOpenOption,
class file /modules/java.base/java/nio/file/StandardOpenOption.class is broken, reading aborted with class java.lang.RuntimeException
bad constant pool index: 0 at pos: 1200
-- [E008] Not Found Error: main.scala:4:30 -------------------------------------
4 |  val x =  StandardOpenOption.CREATE
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^
  |   value CREATE is not a member of object java.nio.file.StandardOpenOption
2 errors found

Expectation

Compiler should provide better error messages when using unsupported JDK version, eg. what is the latest supported version and which version was found in the classfile along with a possible way to mitigate this issue, eg. please try to use the latest version the Scala compiler

@WojciechMazur WojciechMazur added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc compat:java labels Sep 19, 2023
@SethTisue
Copy link
Member

agree. a language newcomer on Discord was bitten by this today

@SethTisue
Copy link
Member

another user bitten today

@bishabosha
Copy link
Member

bishabosha commented Sep 29, 2023

So we could add another constant in ClassfileConstants, and check it when we parse the header?

@bishabosha bishabosha self-assigned this Sep 29, 2023
@bishabosha
Copy link
Member

Alternatively only when there is an error from reading a classfile, then we add an addendum to say that the version was unexpected, so could be the reason?

@bishabosha bishabosha added the better-errors Issues concerned with improving confusing/unhelpful diagnostic messages label Oct 10, 2023
bishabosha added a commit that referenced this issue Nov 3, 2023
when reading a classfile causes a runtime exception, report the version
of the classfile, and request that the user checks JDK compatibility.

Considerations:
- should we test this?

currently we have no process for testing latest JDK, currently we still
only test with JDK 16 and 8

fixes #18573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages compat:java itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants