A simple 1 file of java code with 1.16.22
public class Main {
public static void main(final String[] args) {
System.out.println(new A( 1L, "Jack").equals(new A(1L, "Jill")));
System.out.println(new A()); //should work with no-arg constructor
}
@Value
@Builder
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public static class A {
Long id;
@EqualsAndHashCode.Include
String name;
}
}
causes
> Task :compileJava FAILED
C:\Users\Admin\IdeaProjects\__TEST\testChains\src\main\java\org\javaee8\validation\Main.java:14: error: Can't translate a class java.lang.Boolean to the expected class java.lang.Boolean
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
^
1 error
stacktrace
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileJava'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:596)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:36)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:98)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:51)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:37)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:156)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:141)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:114)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
... 29 more
The same problem happens in Intellij Idea(Not only gradle).
So just to confirm, this didn't make it in time for 1.18?
I don't get an error, but setting onlyExplicitlyIncluded to true has no effect - the equals and hashcode methods are still using all fields (when I run Delombok in IntelliJ).
EDIT: Actually, even manually marking them with @EqualsAndHashCode.Exclude still includes the fields when I DeLombok.
Delombok in IntelliJ use a lombok-intellij-plugin and it always worked horrible (not saying that at least it uses older version of lombok or even just some internal considerations which doesn't know new stuff). Use the 'java -jar lombok.jar..' It will produce the proper result.
That makes sense. Though if the IntelliJ plugin has this problem, does it
also mean that this will behave the same way when I Run/Debug from within
IntelliJ? If so, then I will have to avoid these particular things until
the plugin itself updated/fixed...
On Thu., 5 Jul. 2018, 10:00 soberich, notifications@github.com wrote:
Delombok in IntelliJ use a lombok-intellij-plugin and it always worked
horrible (not saying that at least it uses older version of lombok which
doesn't know new stuff). Use the 'java -jar lombok.jar..' It will produce
the proper result.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/rzwitserloot/lombok/issues/1709#issuecomment-402573682,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB_uhLs7TBSYA4E0V_Th5ddB4AZdil02ks5uDVcngaJpZM4UT-cW
.
For those who Googled this up: It is fixed in 1.18.4 .
I still see this problem in 1.18.6 I slightly rewrote the test from above
public static void main(final String[] args) {
System.out.println(new A( 1L, "Jack").equals(new A(1L, "Jill")));
}
@Value
@Builder
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public static class A {
@EqualsAndHashCode.Include
Long id;
@EqualsAndHashCode.Exclude // Bug happens no matter if this is set or not
String name;
}
Output:
false
Should be true as the id should be the only field included.
"onlyExplicitlyIncluded" is completely disregarded. It also doesn't matter if the field is annotated with "@EqualsAndHashCode.Exclude", the field is always included.
This is a very problematic bug causing hard to track down problems in production when .equals() shows unexpected behaviour. Just noticed it by chance having a detached JPA entity where equals() throwed an exception trying to walk an excluded, lazy-loaded relation field in order to calculate the hash. So please add a test case or remove the option altogether if doesn't work reliably.
@sierracc This is correct ) (AFAIK)
In 1.18 it IS broken. So you need to update to 1.18.4.
@soberich: Thanks, the I missed posting the minor version.
Actually I'm seeing this in current 1.18.6 with Eclipse+Maven.
Update: I also checked that my Eclipse Lombok plugin isn't culprit - it was old (1.16.20), but updating to the current one (1.18.6) and a restart didn't change anything about the problem.
Cannot reproduce. Tried in both eclipse2019.03 and javac12 with 1.18.7 (current master branch):
package test;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Value;
@Value
@Builder
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Test {
@EqualsAndHashCode.Include String x;
String y;
public static void main(String[] args) {
System.out.println(new Test("a", "b").equals(new Test("a", "c")));
System.out.println(new Test("a", "b").equals(new Test("b", "b")));
}
}
I am using Lombok 1.18.6 in a maven multi module project with JDK 8.
@ToString(onlyExplicitlyIncluded = true)
can not compile:
Can't translate a class java.lang.Boolean to the expected class java.lang.Boolean
Workaround:
When i put die lombok dependency into the pom.xml of the module where the annotation is used, then project will compile!
It also works when i provide the lombok dependency in the parent pom.xml
I'm confused: What other option is there beside a) putting Lombok in the module POM, and b) putting it in the parent POM?
@janrieke
i had this case which lead to the compile error (" can't translate a class...")
|--module_commons <- put here the lombok dependency
|--module_a <- using module_commons.
|--module_b
module_a was using (onlyExplicitlyIncluded = true)
That's a setup which is not supported. Lombok must be added as provided dependency, and those dependencies are not transitive.
You have to declare the Lombok dependency explicitly, either in the module or parent POM.
Most helpful comment
For those who Googled this up: It is fixed in 1.18.4 .