Skip to content

Commit

Permalink
[fixes #3748] Patch SourceTypeConverter to avoid parsing empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Sep 19, 2024
1 parent 1ac3950 commit 6522b82
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,14 @@ private static void patchFixSourceTypeConverter(ScriptManager sm) {
.target(new MethodTarget(SOURCE_TYPE_CONVERTER_SIG, "convertAnnotations", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG))
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "convertAnnotations", ANNOTATION_SIG + "[]", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG))
.request(StackRequest.PARAM1, StackRequest.RETURN_VALUE).build());

sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
.target(new MethodTarget(SOURCE_TYPE_CONVERTER_SIG, "parseMemberValue", "org.eclipse.jdt.internal.compiler.ast.Expression", "char[]"))
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isEmpty", "boolean", "char[]"))
.valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnNullExpression", "org.eclipse.jdt.internal.compiler.ast.Expression", "java.lang.Object"))
.request(StackRequest.PARAM1)
.transplant()
.build());
}

private static void patchEclipseDebugPatches(ScriptManager sm) {
Expand Down
8 changes: 8 additions & 0 deletions src/eclipseAgent/lombok/launch/PatchFixesHider.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,14 @@ public static Annotation[] convertAnnotations(Annotation[] out, IAnnotatable ann
return replace;
}

public static boolean isEmpty(char[] array) {
return array.length == 0;
}

public static Expression returnNullExpression(Object string) {
return null;
}

public static String getRealNodeSource(String original, org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
if (!isGenerated(node)) return original;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pkg;

import lombok.Synchronized;

public class ClassWithSynchronized {
@Synchronized
public void test() {
}
}
10 changes: 10 additions & 0 deletions test/eclipse/resource/noerrors/synchronizedUsage/Usage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pkg;

public class Usage {
private ClassWithSynchronized test;

// Prevent "The value of the field Usage.test is not used"
public void test() {
test.test();
}
}
15 changes: 12 additions & 3 deletions test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
*/
package lombok.eclipse.compile;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.jdt.core.ICompilationUnit;
Expand All @@ -49,15 +50,23 @@ public void fieldNameConstantsInAnnotation() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java");

List<IProblem> problems = collectProblems(cu);
assertTrue(problems.isEmpty());
assertEquals(Collections.emptyList(), problems);
}

@Test
public void builderJavadoc() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java");

List<IProblem> problems = collectProblems(cu);
assertTrue(problems.isEmpty());
assertEquals(Collections.emptyList(), problems);
}

@Test
public void synchronizedUsage() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java");

List<IProblem> problems = collectProblems(cu);
assertEquals(Collections.emptyList(), problems);
}

private List<IProblem> collectProblems(ICompilationUnit cu) throws JavaModelException {
Expand Down

0 comments on commit 6522b82

Please sign in to comment.