Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Eclipse 4.27] Lombok ignores lombok.config #3332

Closed
snjeza opened this issue Jan 19, 2023 · 18 comments · Fixed by #3347
Closed

[Eclipse 4.27] Lombok ignores lombok.config #3332

snjeza opened this issue Jan 19, 2023 · 18 comments · Fixed by #3347
Milestone

Comments

@snjeza
Copy link

snjeza commented Jan 19, 2023

Related issues:

Related Eclipse N&N - https://www.eclipse.org/eclipse/news/4.27/jdt.php#ecj-separated-from-core

Steps to reproduce:

You will see LOG cannot be resolve.
The issue can't be reproduced in Eclipse 4.26

@snjeza
Copy link
Author

snjeza commented Jan 19, 2023

A potential patch:

diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java
index 4a0854a4..5ac5b816 100644
--- a/src/core/lombok/eclipse/EclipseAST.java
+++ b/src/core/lombok/eclipse/EclipseAST.java
@@ -21,7 +21,10 @@
  */
 package lombok.eclipse;
 
+import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
+
 import java.io.File;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URI;
@@ -30,13 +33,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import lombok.core.AST;
-import lombok.core.LombokImmutableList;
-import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
-import lombok.permit.Permit;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -55,11 +51,25 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
 import org.eclipse.jdt.internal.compiler.ast.Wildcard;
 
+import lombok.core.AST;
+import lombok.core.LombokImmutableList;
+import lombok.permit.Permit;
+
 /**
  * Wraps around Eclipse's internal AST view to add useful features as well as the ability to visit parents from children,
  * something Eclipse own AST system does not offer.
  */
 public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> {
+	private static ClassLoader jdtCoreClassLoader;
+
+	public static ClassLoader getJdtCoreClassLoader() {
+		return jdtCoreClassLoader;
+	}
+
+	public static void setJdtCoreClassLoader(ClassLoader jdtCoreClassLoader) {
+		EclipseAST.jdtCoreClassLoader = jdtCoreClassLoader;
+	}
+
 	/**
 	 * Creates a new EclipseAST of the provided Compilation Unit.
 	 * 
@@ -188,7 +198,41 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> {
 				return null;
 			}
 			try {
-				return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)).getLocationURI();
+				if (jdtCoreClassLoader != null) {
+					Class<?> resourcePlugin = jdtCoreClassLoader.loadClass("org.eclipse.core.resources.ResourcesPlugin");
+					if (resourcePlugin != null) {
+						Method getWorkspace = resourcePlugin.getMethod("getWorkspace", new Class<?>[0]);
+						Object workspace = getWorkspace.invoke(resourcePlugin,  new Object[0]);
+						if (workspace != null) {
+							Method getRoot = workspace.getClass().getMethod("getRoot", new Class<?>[0]);
+							Object root = getRoot.invoke(workspace,   new Object[0]);
+							if (root != null) {
+								Class<?> pathClass = jdtCoreClassLoader.loadClass("org.eclipse.core.runtime.Path");
+								if (pathClass != null) {
+									Constructor<? extends Object> constructor = pathClass.getConstructor(path.getClass());
+									if (constructor != null) {
+										Object pathObject = constructor.newInstance(path);
+										if (pathObject != null) {
+											Class<?> iPath = jdtCoreClassLoader.loadClass("org.eclipse.core.runtime.IPath");
+											Method getFile = root.getClass().getSuperclass().getMethod("getFile", iPath);
+											if (getFile != null) {
+												Object fileObject = getFile.invoke(root, pathObject);
+												if (fileObject != null) {
+													Method getLocationUri = fileObject.getClass().getMethod("getLocationURI", new Class<?>[0]);
+													Object uri = getLocationUri.invoke(fileObject,  new Object[0]);
+													if (uri instanceof URI) {
+														return (URI)uri;
+													}
+												}
+											}
+										}
+									}
+								}
+							}
+						}
+					}
+				}
+				return null; // return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)).getLocationURI();
 			} catch (Exception e) {
 				// One of the exceptions that can occur is IllegalStateException (during getWorkspace())
 				// if you try to run this while eclipse is shutting down.
diff --git a/src/launch/lombok/launch/Main.java b/src/launch/lombok/launch/Main.java
index af65bdf8..774f7775 100644
--- a/src/launch/lombok/launch/Main.java
+++ b/src/launch/lombok/launch/Main.java
@@ -24,6 +24,8 @@ package lombok.launch;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 
+import lombok.eclipse.EclipseAST;
+
 class Main {
 	private static ShadowClassLoader classLoader;
 	
@@ -37,6 +39,7 @@ class Main {
 	static synchronized void prependClassLoader(ClassLoader loader) {
 		getShadowClassLoader();
 		classLoader.prependParent(loader);
+		EclipseAST.setJdtCoreClassLoader(classLoader);
 	}
 	
 	public static void main(String[] args) throws Throwable {

@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 21, 2023

@snjeza Thanks for the report and the workaround.

I had already noticed the separation of the packages but I thought I had time until the release of the next Eclipse version to investigate the impact on Lombok. Seems like I was wrong about that... Do you know if you plan to update to other preview versions in the future?

I hope that we can fix this fast but I guess we also need to change the test system because of the new dependency...

I also noticed that there are some lombok specific changes in jdtls. If there is anything we can do to optimize the support for jdtls please let us know.

@snjeza
Copy link
Author

snjeza commented Jan 21, 2023

@Rawi01 I have created a PR for you. The PR should work with older versions of JDT.

I also noticed that there are some lombok specific changes in jdtls. If there is anything we can do to optimize the support for jdtls please let us know.

cc @jdneo @XiaoYuhao

Rawi01 added a commit to Rawi01/lombok that referenced this issue Feb 8, 2023
The latest eclipse version properly splits the jdt.core module and the
compiler. To load jdt.core classes during compilation the compiler SCL
needs a reference to the jdt.core SCL.
@testforstephen
Copy link

I also noticed that there are some lombok specific changes in jdtls. If there is anything we can do to optimize the support for jdtls please let us know.

Hi @Rawi01, This is Jinbo, one of project lead of jdtls project. Yes, we have integrated the Lombok support in jdtls by default by using lombok-1.18.24.jar. This benefits Lombok users a lot, thanks for the great work on lombok project.

And usually jdtls offers a monthly release cadence and we are willing to integrate new versions of Lombok as soon as they are ready.

I'm wondering there is a way to speed up this lombok patch as it has affected lots of vscode Java users?

@luca-bassoricci
Copy link

Is there any ETA?

@MagnesiaReal
Copy link

Downgrade the version of eclipse to 2022-09 or 2022-12, it works for me.

rspilker pushed a commit that referenced this issue Mar 21, 2023
The latest eclipse version properly splits the jdt.core module and the
compiler. To load jdt.core classes during compilation the compiler SCL
needs a reference to the jdt.core SCL.
@s3curitybug
Copy link

Could we get a release with this? I upgraded my Eclipse and I'm having troubles reverting the upgrade, so I cannot work. I guess there are more people in this situation.

@rspilker
Copy link
Collaborator

rspilker commented Mar 22, 2023

If I am correct, the fix has already been merged. We expect to publish an edge release later today.

@rzwitserloot rzwitserloot added this to the next-version milestone Mar 23, 2023
@rzwitserloot
Copy link
Collaborator

Available on edge.

@danibs
Copy link

danibs commented Mar 25, 2023

I tried with Eclipse:
Version: 2023-03 (4.27.0)
Build id: 20230309-1520

Lombok:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.3-b01-101 (Apple Inc.)
Premain-Class: lombok.launch.Agent
Agent-Class: lombok.launch.Agent
Can-Redefine-Classes: true
Main-Class: lombok.launch.Main
Lombok-Version: 1.18.27
Automatic-Module-Name: lombok

As you can see, still doesn't work. setC1() return void instead of class it-self

immagine

@thomseno
Copy link

I tried with Eclipse: Version: 2023-03 (4.27.0) Build id: 20230309-1520

Lombok: Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.1 Created-By: 14.3-b01-101 (Apple Inc.) Premain-Class: lombok.launch.Agent Agent-Class: lombok.launch.Agent Can-Redefine-Classes: true Main-Class: lombok.launch.Main Lombok-Version: 1.18.27 Automatic-Module-Name: lombok

As you can see, still doesn't work. setC1() return void instead of class it-self

immagine

Maybe I'm missing something, but isn't that the definition of a setter? 🤔

@danibs
Copy link

danibs commented Mar 25, 2023

Maybe I'm missing something, but isn't that the definition of a setter? thinking

Not using Lombok 😉 (when it works)

immagine

@thomseno
Copy link

thomseno commented Mar 25, 2023

Maybe I'm missing something, but isn't that the definition of a setter? thinking

Not using Lombok 😉 (when it works)

immagine

🫣 My bad, wasn’t aware of the @Accessors feature.

@danibs
Copy link

danibs commented Mar 27, 2023

Sorry, my mistake! 😢
The .ini file was configured with the wrong path of Lombok...
Fixed that, it works for me too.

Sorry again...

Hamled pushed a commit to Hamled/lombok that referenced this issue Apr 2, 2023
The latest eclipse version properly splits the jdt.core module and the
compiler. To load jdt.core classes during compilation the compiler SCL
needs a reference to the jdt.core SCL.
This was referenced Apr 13, 2023
@mxmlnglt
Copy link

Available on edge.

Repo URL is down... you can only download the .jar by yourself... see #3414

@janrieke
Copy link
Contributor

Lombok 1.18.28 has been released and includes this bugfix.

@mxmlnglt
Copy link

Lombok 1.18.28 has been released and includes this bugfix.

OK great!!! (at last...!)

@sandipubale
Copy link

I had same problem while using 1.18.4, however, after using version 1.18.24 all problems vanished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet