Fix broken logic that uses null owner class
Fixes https://github.com/spring-projects/spring-loaded/issues/173 Fixes https://github.com/spring-projects/spring-loaded/issues/187 Fixes https://github.com/spring-projects/spring-loaded/issues/175§
This commit is contained in:
@@ -150,8 +150,8 @@ public class Java8 {
|
||||
if (null == ownerRType || !ownerRType.hasBeenReloaded()) {
|
||||
// target containing the reference/lambdaMethod has not been reloaded, no need to get over
|
||||
// complicated.
|
||||
Class<?> ownerClazz = ownerRType.getClazz();
|
||||
implMethod = caller.findVirtual(ownerClazz, name, implMethodType);
|
||||
Class<?> clazz = callerLoader.loadClass(owner.replace("/", "."));
|
||||
implMethod = caller.findVirtual(clazz, name, implMethodType);
|
||||
}
|
||||
else {
|
||||
MethodMember targetReferenceMethodMember = ownerRType.getCurrentMethod(name, descriptor);
|
||||
|
||||
@@ -68,6 +68,26 @@ public class Java8Tests extends SpringLoadedTests {
|
||||
// TODO should assert something but the issue is that the JVM crashes...
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue173() throws Exception {
|
||||
String t = "bugs.Issue173";
|
||||
TypeRegistry typeRegistry = getTypeRegistry(t);
|
||||
byte[] sc = loadBytesForClass(t);
|
||||
ReloadableType rtype = typeRegistry.addType(t, sc);
|
||||
|
||||
Class<?> clazz = rtype.getClazz();
|
||||
@SuppressWarnings("unused")
|
||||
Result r = runUnguarded(clazz, "run");
|
||||
|
||||
r = runUnguarded(clazz, "run");
|
||||
|
||||
rtype.loadNewVersion("002", rtype.bytesInitial);
|
||||
|
||||
r = runUnguarded(clazz, "run");
|
||||
|
||||
assertEquals("https://www.redacted.com/path", r.returnValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callBasicType() throws Exception {
|
||||
String t = "basic.FirstClass";
|
||||
|
||||
49
testdata-java8/src/main/java/bugs/Issue173.java
Normal file
49
testdata-java8/src/main/java/bugs/Issue173.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package bugs;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Issue173 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(run());
|
||||
}
|
||||
|
||||
public static String run() {
|
||||
return url("path").toString();
|
||||
}
|
||||
|
||||
public static URI url(Object... args) {
|
||||
try {
|
||||
/* flattening the paths */
|
||||
final List<String> paths = Arrays
|
||||
.stream(args)
|
||||
.flatMap(arg -> {
|
||||
if (arg instanceof Collection) {
|
||||
return ((Collection<Object>) arg).stream();
|
||||
} else if (arg instanceof Object[]) {
|
||||
return Arrays.stream((Object[]) arg);
|
||||
}
|
||||
|
||||
return Arrays.stream(new Object[]{
|
||||
arg
|
||||
});
|
||||
})
|
||||
.map(Object::toString)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Path path = Paths.get("/", paths.toArray(new String[0]));
|
||||
URI uri = new URI("https", "www.redacted.com", path.toString(), null);
|
||||
|
||||
return uri;
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user