Fix crash when lambda is not used. Fix #500

This commit is contained in:
Alexey Andreev 2020-06-01 12:19:37 +03:00
parent 6f7c2dff2b
commit 5ee332c771
2 changed files with 8 additions and 1 deletions

View File

@ -920,7 +920,8 @@ public abstract class DependencyAnalyzer implements DependencyInfo {
arguments, indy.getBootstrapMethod(), indy.getBootstrapArguments(),
agent);
ValueEmitter result = substitutor.substitute(callSite, pe);
if (result.getVariable() != null && result.getVariable() != indy.getReceiver()) {
if (result.getVariable() != null && result.getVariable() != indy.getReceiver()
&& indy.getReceiver() != null) {
AssignInstruction assign = new AssignInstruction();
assign.setAssignee(result.getVariable());
assign.setReceiver(indy.getReceiver());

View File

@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.function.Consumer;
import java.util.function.IntPredicate;
import java.util.function.Supplier;
import org.junit.Test;
@ -72,6 +73,11 @@ public class LambdaTest {
assertArrayEquals(new int[] { 1, 2, 3 }, array);
}
@Test
public void unusedLambda() {
Consumer<String> foo = bar -> { };
}
private String acceptIntPredicate(IntPredicate p) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; ++i) {