Skip to content

Commit

Permalink
Avoid generate @DeleGate method body NPE when deletegate target is nu…
Browse files Browse the repository at this point in the history
…ll on ecj's HandleDelegate
  • Loading branch information
eeoun committed Jan 17, 2025
1 parent 6d2add1 commit f426b66
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.Argument;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.BinaryExpression;
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
Expand Down Expand Up @@ -698,16 +702,24 @@ argName, pos(source),
method.arguments[method.arguments.length - 1].type.bits |= ASTNode.IsVarArgs;
}
}


boolean useReturn = false;
Statement body;
if (method.returnType instanceof SingleTypeReference && ((SingleTypeReference)method.returnType).token == TypeConstants.VOID) {
body = call;
} else {
useReturn = true;
body = new ReturnStatement(call, source.sourceStart, source.sourceEnd);
setGeneratedBy(body, source);
}

method.statements = new Statement[] {body};

Statement nullCheckAndReturn = new IfStatement(new BinaryExpression(
new NullLiteral(0, 0), call.receiver, OperatorIds.EQUAL
), new ReturnStatement(
useReturn ? new NullLiteral(0, 0) : null, 0, 0
), 0, 0);

method.statements = new Statement[] {nullCheckAndReturn,body};
return method;
}

Expand Down

0 comments on commit f426b66

Please sign in to comment.