diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index a216ebba..ca99193a 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -41,10 +41,10 @@ jobs: runs-on: ubuntu-24.04 needs: build env: - EA_JDK: 23 + EA_JDK: 24 strategy: matrix: - jdk: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] + jdk: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] goal: [javacCurrent] include: - jdk: 11 diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 5c9f80c6..fff1846a 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2022 The Project Lombok Authors. + * Copyright (C) 2009-2025 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -592,38 +592,42 @@ public class JavacHandlerUtil { private static final Field astField; private static final Field originalAnnos; - private static final Method findRecordComponentToRemove; + private static final Method getRecordComponents = Permit.permissiveGetMethod(ClassSymbol.class, "getRecordComponents"); static { Field a = null; Field o = null; - Method m = null; try { Class forName = Class.forName("com.sun.tools.javac.code.Symbol$RecordComponent"); a = Permit.permissiveGetField(forName, "ast"); o = Permit.permissiveGetField(forName, "originalAnnos"); - m = Permit.permissiveGetMethod(ClassSymbol.class, "findRecordComponentToRemove", JCVariableDecl.class); } catch (Throwable e) { // Ignore } astField = a; originalAnnos = o; - findRecordComponentToRemove = m; } static void deleteAnnotation(JCClassDecl record, JCVariableDecl component, JCTree annotation) { - if ((astField == null && originalAnnos == null) || findRecordComponentToRemove == null) return; + if ((astField == null && originalAnnos == null) || getRecordComponents == null) return; try { - Object toRemove = Permit.invokeSneaky(findRecordComponentToRemove, record.sym, component); - if (astField != null) { - // OpenJDK - JCVariableDecl variable = Permit.get(astField, toRemove); - variable.mods.annotations = filterListByPos(variable.mods.annotations, annotation); - } else { - // Zulu JDK 17 - List annotations = Permit.get(originalAnnos, toRemove); - Permit.set(originalAnnos, toRemove, filterListByPos(annotations, annotation)); + List recordComponents = (List) Permit.invokeSneaky(getRecordComponents, record.sym); + + for (Object recordComponent : recordComponents) { + Name recordComponentName = ((Symbol) recordComponent).name; + if (!recordComponentName.equals(component.name)) continue; + + if (astField != null) { + // OpenJDK + JCVariableDecl variable = Permit.get(astField, recordComponent); + variable.mods.annotations = filterListByPos(variable.mods.annotations, annotation); + } else { + // Zulu JDK 17 + List annotations = Permit.get(originalAnnos, recordComponent); + Permit.set(originalAnnos, recordComponent, filterListByPos(annotations, annotation)); + } + return; } } catch (Throwable e) { // Ignore diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index f7834687..d8b4740c 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2024 The Project Lombok Authors. + * Copyright (C) 2009-2025 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -184,7 +184,16 @@ public class Javac { public static final TypeTag CTC_NONE = typeTag("NONE"); public static final TypeTag CTC_BOT = typeTag("BOT"); public static final TypeTag CTC_ERROR = typeTag("ERROR"); - public static final TypeTag CTC_UNKNOWN = typeTag("UNKNOWN"); + public static final TypeTag CTC_UNKNOWN; // Removed in JDK24 + static { + TypeTag unknonwTypeTag = null; + try { + unknonwTypeTag = typeTag("UNKNOWN"); + } catch (Exception e) { + if (!(e instanceof NoSuchFieldException)) throw Javac.sneakyThrow(e); + } + CTC_UNKNOWN = unknonwTypeTag; + } public static final TypeTag CTC_UNDETVAR = typeTag("UNDETVAR"); public static final TypeTag CTC_CLASS = typeTag("CLASS"); diff --git a/src/utils/lombok/javac/TreeMirrorMaker.java b/src/utils/lombok/javac/TreeMirrorMaker.java index 44e26ab6..798a687a 100644 --- a/src/utils/lombok/javac/TreeMirrorMaker.java +++ b/src/utils/lombok/javac/TreeMirrorMaker.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2021 The Project Lombok Authors. + * Copyright (C) 2010-2025 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -105,7 +105,7 @@ public class TreeMirrorMaker extends TreeCopier { boolean wipeSymAndType = copy.type.isErroneous(); if (!wipeSymAndType) { TypeTag typeTag = TypeTag.typeTag(copy.type); - wipeSymAndType = (CTC_NONE.equals(typeTag) || CTC_ERROR.equals(typeTag) || CTC_UNKNOWN.equals(typeTag) || CTC_UNDETVAR.equals(typeTag)); + wipeSymAndType = (typeTag.equals(CTC_NONE) || typeTag.equals(CTC_ERROR) || typeTag.equals(CTC_UNKNOWN) || typeTag.equals(CTC_UNDETVAR)); } if (wipeSymAndType) {