mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 03:13:38 +00:00
[#4040] Fixed: Javac26 would fail to eliminate the runtime dep when using @SneakyThrows.
This commit is contained in:
2 files changed
+31
-10
No files matched your search
@@ -2,7 +2,7 @@ Lombok Changelog
|
||||
----------------
|
||||
|
||||
### v1.18.47 "Edgy Guinea Pig"
|
||||
* No changes since v1.18.46 yet.
|
||||
* BUGFIX: `@SneakyThrows` usage on JDK26 no longer results in class files that require `lombok.jar` to be on the runtime classpath (which should not be neccessary). [#4040](https://github.com/projectlombok/lombok/issues/4022).
|
||||
|
||||
### v1.18.46 (April 22nd, 2026)
|
||||
* PLATFORM: JDK26 support added [#4019](https://github.com/projectlombok/lombok/issues/4019).
|
||||
|
||||
@@ -56,6 +56,7 @@ import com.sun.tools.javac.processing.JavacFiler;
|
||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Context.Key;
|
||||
|
||||
import lombok.Lombok;
|
||||
import lombok.core.CleanupRegistry;
|
||||
@@ -171,17 +172,19 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
Field filerFileManagerField = Permit.getField(JavacFiler.class, "fileManager");
|
||||
filerFileManagerField.set(javacFiler, newFilerManager);
|
||||
|
||||
if (lombok.javac.Javac.getJavaCompilerVersion() > 8
|
||||
&& !lombok.javac.handlers.JavacHandlerUtil.inNetbeansCompileOnSave(context)) {
|
||||
replaceFileManagerJdk9(context, newFilerManager);
|
||||
}
|
||||
if (lombok.javac.handlers.JavacHandlerUtil.inNetbeansCompileOnSave(context)) return;
|
||||
|
||||
replaceFileManagerJdk(context, newFilerManager);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw Lombok.sneakyThrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceFileManagerJdk9(Context context, JavaFileManager newFiler) {
|
||||
private void replaceFileManagerJdk(Context context, JavaFileManager newFiler) {
|
||||
int v = lombok.javac.Javac.getJavaCompilerVersion();
|
||||
if (v < 9) return;
|
||||
|
||||
try {
|
||||
JavaCompiler compiler = (JavaCompiler) Permit.invoke(Permit.getMethod(JavaCompiler.class, "instance", Context.class), null, context);
|
||||
try {
|
||||
@@ -191,10 +194,8 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
catch (Exception e) {}
|
||||
|
||||
try {
|
||||
Field writerField = Permit.getField(JavaCompiler.class, "writer");
|
||||
ClassWriter writer = (ClassWriter) writerField.get(compiler);
|
||||
Field fileManagerField = Permit.getField(ClassWriter.class, "fileManager");
|
||||
Permit.set(fileManagerField, writer, newFiler);
|
||||
if (v > 25) replaceFileManagerJdk26(context, compiler, newFiler);
|
||||
else replaceFileManagerJdk9(context, compiler, newFiler);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
@@ -202,6 +203,26 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceFileManagerJdk9(Context context, JavaCompiler compiler, JavaFileManager newFiler) throws NoSuchFieldException, IllegalAccessException {
|
||||
Field writerField = Permit.getField(JavaCompiler.class, "writer");
|
||||
ClassWriter writer = (ClassWriter) writerField.get(compiler);
|
||||
|
||||
Field fileManagerField = Permit.getField(ClassWriter.class, "fileManager");
|
||||
Permit.set(fileManagerField, writer, newFiler);
|
||||
}
|
||||
|
||||
private void replaceFileManagerJdk26(Context context, JavaCompiler compiler, JavaFileManager newFiler) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
|
||||
Field writerField = Permit.getField(JavaCompiler.class, "writer");
|
||||
|
||||
// Setting final fields is... tricky on JDK26+
|
||||
@SuppressWarnings("unchecked")
|
||||
Context.Key<ClassWriter> classWriterKey = (Key<ClassWriter>) Permit.getField(ClassWriter.class, "classWriterKey").get(null);
|
||||
context.put(classWriterKey, (ClassWriter) null);
|
||||
ClassWriter writer = ClassWriter.instance(context);
|
||||
context.put(ClassWriter.class, writer);
|
||||
writerField.set(compiler, writer);
|
||||
}
|
||||
|
||||
private void forceMultipleRoundsInNetBeansEditor() {
|
||||
try {
|
||||
Field f = Permit.getField(JavacProcessingEnvironment.class, "isBackgroundCompilation");
|
||||
|
||||
Reference in new issue
Block a user