Skip to content

Commit

Permalink
Fix NPE when using an abstract function class that implements an inte…
Browse files Browse the repository at this point in the history
…rface.
  • Loading branch information
Cybermaxke committed May 16, 2021
1 parent b650edb commit 5315d9f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static void findClassMethods(@NonNull Class<?> functionClass, @NonNull M
findClassMethods(interf, methods);
}
final Class<?> superclass = functionClass.getSuperclass();
if (superclass != Object.class) {
if (superclass != null && superclass != Object.class) {
findClassMethods(superclass, methods);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.lanternpowered.lmbda.test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
Expand All @@ -33,11 +34,20 @@

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.function.ToIntFunction;

class LambdaAbstractFunctionGetterTest {

@Test
void test() throws Exception {
void testFindMethod() {
assertDoesNotThrow(() -> LambdaType.of(MyFunction.class),
"Unable to find function method in abstract class");
assertDoesNotThrow(() -> LambdaType.of(MyToIntFunction.class),
"Unable to find function method in abstract class which implements an interface");
}

@Test
void testGetter() throws Exception {
final MethodHandles.Lookup lookup = MethodHandlesExtensions.privateLookupIn(TestObject.class, MethodHandles.lookup());
final MethodHandle methodHandle = lookup.findGetter(TestObject.class, "data", int.class);

Expand All @@ -53,7 +63,7 @@ public static class TestObject {

private int data = 100;

void setData(int value) {
void setData(final int value) {
this.data = value;
}
}
Expand All @@ -62,4 +72,14 @@ abstract static class MyFunction {

public abstract int getValue(TestObject testObject);
}

abstract static class MyToIntFunction implements ToIntFunction<TestObject> {

@Override
public int applyAsInt(TestObject value) {
return getValue(value);
}

public abstract int getValue(TestObject testObject);
}
}

0 comments on commit 5315d9f

Please sign in to comment.