Skip to content

In Java 24 and above any rewrite-java module will fail with ClassNoDefFoundError: Type.UnknownType #4768

Closed

Description

@Col-E

In JDK 24 per this commit in October (Respective PR) the Type.UnknownType has been removed, and its usage has been swapped out with Type.ErrorType.

Example stacktrace:

java.lang.NoClassDefFoundError: com/sun/tools/javac/code/Type$UnknownType
  org.openrewrite.java.isolated.ReloadableJava21TypeMapping.type(ReloadableJava21TypeMapping.java:49)
  org.openrewrite.java.isolated.ReloadableJava21TypeMapping.type(ReloadableJava21TypeMapping.java:387)
  org.openrewrite.java.isolated.ReloadableJava21TypeMapping.type(ReloadableJava21TypeMapping.java:380)
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitMemberSelect(ReloadableJava21ParserVisitor.java:894)
  org.openrewrite.java.isolated.ReloadableJava21ParserVisitor.visitMemberSelect(ReloadableJava21ParserVisitor.java:75)
  com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2585)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)

Activity

  1. added
    bug
    on Dec 11, 2024
  2. timtebeek commented on Dec 11, 2024

    @timtebeek
    Member

    Thanks for referencing those external sources @Col-E ! Really helpful to gauge the adjustments we'll have to make here.

    It looks like there's two classes in our Java 21 parser that use that Type.UnknownType; here's the first usages for each file:

    private String signature(@Nullable Type type) {
    if (type == null || type instanceof Type.UnknownType || type instanceof NullType) {
    return "{undefined}";

    public JavaType type(com.sun.tools.javac.code.@Nullable Type type) {
    if (type == null || type instanceof Type.ErrorType || type instanceof Type.PackageType || type instanceof Type.UnknownType ||
    type instanceof NullType) {
    return JavaType.Class.Unknown.getInstance();
    }

    I'm not yet sure if this is merely the first, or the only adjustment we'll have to make. If it's the only change then we can look to do something similar as we did for Java 23, to support that using our existing Java 21 parser.

    If we expect more changes, then it might make sense to fork the Java 21 parser and start a Java 24 parser without these removed type references. The best time to fork the Java 21 parser is likely after we add Lombok & JEP-440 & JEP-441 support there. Getting the timing right ensures there's less work to maintain those forks in parallel as we build out their capabilities. Lombok support is already in our Java 17 parser; these PRs track further additions to our parsers

    There's some additional context also in openrewrite/rewrite-templating#118.

  3. moved this to Backlog in OpenRewriteon Dec 11, 2024
  4. triceo commented on Apr 15, 2025

    @triceo

    Is there any estimate when we can expect this fixed? Is there progress being made?
    This is blocking migration to Java 24 and I wouldn't expect this from such a high profile and otherwise well-maintained project.

  5. timtebeek commented on Apr 15, 2025

    @timtebeek
    Member

    Thanks! I'll cross link to the comment I'd posted here earlier.

    The steps are clear, and likely not very complicated at this point, but it's not been a priority for us just yet. We see most demand moving to "LTS" versions, so 8, 11, 17, 21, 25, and where reasonably possible accommodate intermediate releases. Right now we're considering either starting an early rewrite-java-25 that then also covers Java 24 (more effort), or apply a similar patch as was seen in openrewrite/rewrite-templating#132 to bring Java 24 support to the parser in rewrite-java-21 (easier).

    Any help of course would be appreciated; you'll know all to well the challenges of working at a startup/scale up and being pulled in all directions, while also having your own (and customers) priorities to tend to.

  6. triceo commented on Apr 15, 2025

    @triceo

    The steps are clear, and likely not very complicated at this point, but it's not been a priority for us just yet. We see most demand moving to "LTS" versions, so 8, 11, 17, 21, 25, and where reasonably possible accommodate intermediate releases.

    My two cents: the approach that focuses on LTS is misguided. We are library maintainers; like it or not, we are key dependencies for many projects. If we decide to skip supporting certain versions of JDK, we force the wider ecosystem to do the same.

    Today, I'm not upgrading to JDK 24, and the cost of upgrade to any future JDK starts accumulating. We've been here before, and some people are still stuck on Java 11, or Java 8 - precisely because of these ever-accumulating upgrade costs.

    My opinion is that, unless we (library maintainers) treat every single JDK release seriously, we are all (as Java developers) forever stuck in the vicious cycle of fearing upgrades, therefore not upgrading, and therefore creating even more reasons to fear upgrades.

    I see this as a key responsibility of me as a library maintainer, and as something that I owe the ecosystem. As such, I consider this a priority in my work. I understand why others may see it differently - the only thing I can do is try to change people's minds.

    Right now we're considering either starting an early rewrite-java-25 that then also covers Java 24 (more effort), or apply a similar patch as was seen in openrewrite/rewrite-templating#132 to bring Java 24 support to the parser in rewrite-java-21 (easier).

    Any help of course would be appreciated; you'll know all to well the challenges of working at a startup/scale up and being pulled in all directions, while also having your own (and customers) priorities to tend to.

    I hear you, and feel your pain. One other thing I learned at a scale-up: shipped is better than perfect. If you say you have a patch you can apply to rewrite-java-21 now, IMO you should do it.

  7. timtebeek commented on Apr 15, 2025

    @timtebeek
    Member

    Thanks for understanding and sharing your perspective; I've brought it up for internal discussion again; you'll see progress logged here if we do pick it up, as we try to work in the open where we can, which includes sharing our position and priorities.

  8. triceo commented on Apr 15, 2025

    @triceo

    Thanks, @timtebeek, much appreciated!

  9. zepfred commented on Apr 15, 2025

    @zepfred
    Contributor

    Hey @timtebeek, thanks for the update! I wonder if I could help in any way here. What are your thoughts on supporting JDK 24, like rewrite-java-24?

    If you're okay with that, I could assess the complexity and determine if I can provide a patch for it.

  10. timtebeek commented on Apr 15, 2025

    @timtebeek
    Member

    Thanks for the offer to help @zepfred ! We're considering one of (at least) two options:

    1. Patch the rewrite-java-21 parser to work despite missing that JavaType UNKNOWN, similar to what was done for rewrite-templating already
      • Likely relatively straightforward; it helps resolve this immediate issue, with minimal duplication to maintain for now
    2. Start a new rewrite-java-25 early, with current support for Java 24, and an eye toward Java 25 to follow in fall
      • Somewhat more work, and a new parser to maintain in parallel, but there's less risk of breaking existing parsing for Java 21-23

    Either could work, depending on what you're most comfortable with. It'd sure be great to cover Java 24 already, and we'll gladly review any work done towards this.

  11. timtebeek commented on Apr 19, 2025

    @timtebeek
    Member

    Thanks again @zepfred ! This will go out with the new release next week.

  12. zepfred commented on Apr 19, 2025

    @zepfred
    Contributor

    Thank you for all your hard work!

  13. moved this from Backlog to Done in OpenRewriteon Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugjavajava 25+parser

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions