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

[BUG] Invalid com.sun.source.tree.LiteralTree generated by lombok? #2695

Comments

@mattiasgronlund
Copy link
Contributor

Describe the bug
When lombok executes as an annotation processor it seems like it produces invalid code.

To Reproduce
At the end of the report, there is a command to extract source.tgz which contains a maven project which shows the problem.

The following sequence should fail:

$ tar zxvf source.tgz
$ mvn compile 
...
The Checker Framework crashed
...
Exception: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Void (java.lang.Integer and java.lang.Void are in module java.base of loader 'bootstrap'); java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Void (java.lang.Integer and java.lang.Void are in module java.base of loader 'bootstrap')
...

But if we move the source the compilation will work:

$ mv src/main/java/test src/main/lombok/
$ mvn compile 
...
BUILD SUCCESS
...

Expected behavior
The expected behavior is that both cases above should work.

Version info (please complete the following information):

  • Lombok version: 1.18.16.0
  • Platform: javac -version => javac 11.0.8
  • Checker framework 3.8.0

Additional context
I have not been able to create a smaller crashing example, I have no clue why the interface and derived types are needed, but I think the @Singular is the root for this problem as the build() method get a lot more complex when @Singular is added (and if I remove it, the problems go away).

I have investigated the crash in checkerframework and got a workaround running, but I get the feeling that this is really a lombok problem.

The workaround in checkerframework is:

diff --git a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/node/NullLiteralNode.java b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/node/NullLiteralNode.java
index 18206dde1..e9596c791 100644
--- a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/node/NullLiteralNode.java
+++ b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/node/NullLiteralNode.java
@@ -27,7 +27,19 @@ public class NullLiteralNode extends ValueLiteralNode {
 
     @Override
     public Void getValue() {
-        return (Void) tree.getValue();
+        Object value = tree.getValue();
+        if (value instanceof Void) {
+
+            return (Void) value;
+        }
+
+        if (value instanceof java.lang.Integer) {
+            System.out.printf("Expected a java.lang.Void value, as type is %s but it has a %s value: %s%n",
+                              tree.getKind(),
+                              value.getClass().getCanonicalName(),
+                              value == null ? "null" : value.toString());
+        }
+        return (Void) null;
     }
 
     @Override

With this patch added the failing build succeeds but outputs:

...
Expected a java.lang.Void value, as type is NULL_LITERAL but it has a java.lang.Integer value: 0
Expected a java.lang.Void value, as type is NULL_LITERAL but it has a java.lang.Integer value: 0
Expected a java.lang.Void value, as type is NULL_LITERAL but it has a java.lang.Integer value: 0
...

Why do I think this is a lombok problem?
For me it seems very strange that checker framework manage to get its hands on a LiteralTree instance which has the kind NULL_LITERAL, which value isn't (Void) null, but instead an (Integer) 0.

Command to extract source.tgz:

base64 -d /tmp/b < <(cat << END
H4sICBXO8V8CA2J1Zy50YXIA7Vvrb+M2Evdn/xWssVhcgYqyJD+6ieI21we6RbIJLtu9AveJlmhb
G1nUkVKcYJH//YZ62bIelh1v3B7ED4FFzgzJmflxZihFcEvtfOXWhzYeDjuaPtD7o36nr42H0BX1
J62jGeOxoff7xngI49pAH3fQsPMKLRQB4Qh1HpckmHNWSUdDQbno/L81AfZfEsdT/wL2HxjGUBuN
YVw3RoPW/q9qf5ctp+xePa39B5quGzBujIxha/9Xtf9n8kDUU+M/s78+Nlr7v779AyoC9ZT2H/aH
0v4DfdjG/1PZ/9IKHOZh2XE8+48Gg0r760M9tT+Efh3GR4Y+6qB+a/+v3nxi3ZM5RdLy592us/QZ
D1CcDOB/ho5rU36+1X3nePPQJXxNL30Fh4Hj4isnkvNjwtr1w6nrWMhyiRAo9iz0pYug/ZiKiZ4S
Oslu3gUchibIJ5wsaQBqP+8+dztteyX8e+89UPqMWPT90nfpksrHF5wHO/FvGFn8748B/7o2GLf4
PwX+83AtdQTkpL9zFCmqbx4o545NN1EdAxqRaxosmP2PbxNa2TgNQu6h3h0DpC+AqncejT13n1tw
nhz/x0kCduFf64828D+Q4/p42OL/dPh3MlQ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ePDh8vrX36OA9HfLpKUfbaRC7Yfqfzn
GcKfUOhBkoCI5yyJqwjPmc3AITZvL5EjUPIaxEYrJ1hE37eIM1VNrvNg++qSfWYLEgo1L0j1Ie1S
32m4XCtJlEAa1t7Jaaac3VPvDO0zgyNESIU6HpXHfDMmxwk5FveOn3hj2cj23V7Z5y/5gyh7lBcU
2dcPk/az5La1rW1ta1vb2ta2trWtbW1rW9vi9j8KETvHAFAAAA==
END
) > source.tgz

@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 4, 2021

Can confirm that this is broken, already identified the root cause and will provide a PR soon. I also don't get why the unreferenced interface is required, thats fascinating 😄

Btw you can also upload files to github, that base64 encode archive was a little bit strange 😄

@mattiasgronlund
Copy link
Contributor Author

Thanks for the extremely quick support!

Sorry for the strange archive, I must have been a bit to focused on the lombok problem to realize that it could be as simple as drag and drop to add an attachment, I saw the Video support, and just didn't read the full line😄.

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