redhat-developer / redhat-developer/vscode-java

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

Đang mở
#3,319 3 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
TypeScript
Star
2.3k
Fork
546
Merge trung bình
20 giờ 1 phút
Pull request đã merge (30 ngày)
11

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện vấn đề với java-sandbox.zip được liên kết, Maybe for Java MRJAR và các Java toolchain 11 và 17. Bắt đầu với Java Project Explorer và lệnh Java: Clean Java Language Server, sau đó theo dõi cách định nghĩa lớp đã import được chọn sau khi chuyển đổi phiên bản. Hoàn tất khi lớp MRJAR tương ứng với phiên bản Java hiện tại được hiển thị.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, typescript, vscode
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.