redhat-developer / redhat-developer/vscode-java

Multi-Release JARs (MRJARs) pick the wrong class on higher Java versions

Ouverte
#3,319 3 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
TypeScript
Étoiles
2.3k
Forks
546
Merge moyen
20 h 1 min
PR mergées (30 j)
11

Description

Libraries in the classpath with a Multi-Release structure work fine when using the lowest allowed Java version. However, when using a higher version that provides a replacement class, VSCode loads the lower version instead of the replacement. Another interesting thing is that when looking at the library on the Java Project Explorer using a higher Java version, classes with a replacement show duplicates, but they all switch back to the lowest when opened.

Environment
  • Operating System: Windows 11 - 22H2 (build 22621.2283)
  • JDK version: v20.0.2 (Gradle Java Toolchain for 11 and 17)
  • Visual Studio Code version: v1.82.2
  • Java extension version: v1.22.1
Steps To Reproduce
  1. Add a Multi-Release JAR dependency to a project.
    • For these steps, I'm using Maybe for Java, which is a library of my authoring. This way, I know the Either interface has a replacement for Java 17, which makes the interface sealed, plus it uses record classes for the implementations.
    • This means that on Java 11, you could make any class implement Either. But on Java 17, trying to implement Either should show a compilation error.
  2. Make sure to use the lowest allowed Java version for the library (e.g., Java 11)
  3. Use the Java Project Explorer to ensure the MRJAR lib has the META-INF/versions folder with replacement classes
  4. Import a class with replacement (e.g., import io.github.joselion.maybe.utils.Either;)
  5. Go to the definition of the imported class. It should show its lowest version (e.g., interface without sealed keyword and no records)
  6. Switch to a higher Java version (e.g., Java 17)
    • Using Gradle and the Java Toolchain can be useful
    • You may need to run the Java: Clean Java Language Server command
  7. Use the Java Project Explorer to verify the META-INF directory does not contain versions anymore
  8. Go to the definition of the imported class again. It still shows the lowest version (e.g., it should show a sealed interface and records instead)

Sample project: java-sandbox.zip

Logs: Nothing is logged during the process

Current Result

MRJAR references the lowest version class when using a higher Java version

Expected Result

MRJAR references should use the matching class based on the current Java version.

Additional Information

I'm willing to help with a PR if someone can point me in the right direction. Knowing where and how this should be handled will be of great help 🙂

I'm also adding some screenshots of the Java Project Explorer with an MRJAR dependency expanded.

With Java 11:
image

With Java 17:
image

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Reproduisez le problème avec le java-sandbox.zip lié, le Maybe for Java MRJAR et les toolchains Java 11 et 17. Commencez avec Java Project Explorer et la commande Java: Clean Java Language Server, puis suivez la manière dont la définition de la classe importée est sélectionnée après le changement de version. C’est terminé lorsque la classe MRJAR correspondante à la version actuelle de Java est affichée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java, typescript, vscode
Domaine
developer-experience, tooling
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.