1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -244,7 +244,7 @@ private void updateExitTypeDescriptor() {
244
244
Method method = ((ReflectiveMethodExecutor ) executorToCheck .get ()).getMethod ();
245
245
String descriptor = CodeFlow .toDescriptor (method .getReturnType ());
246
246
if (this .nullSafe && CodeFlow .isPrimitive (descriptor )) {
247
- originalPrimitiveExitTypeDescriptor = descriptor ;
247
+ this . originalPrimitiveExitTypeDescriptor = descriptor ;
248
248
this .exitTypeDescriptor = CodeFlow .toBoxedDescriptor (descriptor );
249
249
}
250
250
else {
@@ -296,7 +296,7 @@ public boolean isCompilable() {
296
296
297
297
return true ;
298
298
}
299
-
299
+
300
300
@ Override
301
301
public void generateCode (MethodVisitor mv , CodeFlow cf ) {
302
302
CachedMethodExecutor executorToCheck = this .cachedExecutor ;
@@ -327,7 +327,7 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
327
327
// Something on the stack when nothing is needed
328
328
mv .visitInsn (POP );
329
329
}
330
-
330
+
331
331
if (CodeFlow .isPrimitive (descriptor )) {
332
332
CodeFlow .insertBoxIfNecessary (mv , descriptor .charAt (0 ));
333
333
}
@@ -340,8 +340,10 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
340
340
}
341
341
342
342
generateCodeForArguments (mv , cf , method , this .children );
343
- mv .visitMethodInsn ((isStaticMethod ? INVOKESTATIC : INVOKEVIRTUAL ), classDesc , method .getName (),
344
- CodeFlow .createSignatureDescriptor (method ), method .getDeclaringClass ().isInterface ());
343
+ mv .visitMethodInsn (
344
+ (isStaticMethod ? INVOKESTATIC : (isJava8DefaultMethod (method ) ? INVOKEINTERFACE : INVOKEVIRTUAL )),
345
+ classDesc , method .getName (), CodeFlow .createSignatureDescriptor (method ),
346
+ method .getDeclaringClass ().isInterface ());
345
347
cf .pushDescriptor (this .exitTypeDescriptor );
346
348
347
349
if (this .originalPrimitiveExitTypeDescriptor != null ) {
@@ -354,6 +356,11 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
354
356
}
355
357
}
356
358
359
+ private static boolean isJava8DefaultMethod (Method method ) {
360
+ return (method .getDeclaringClass ().isInterface () && Modifier .isPublic (method .getModifiers ()) &&
361
+ !Modifier .isAbstract (method .getModifiers ()) && !Modifier .isStatic (method .getModifiers ()));
362
+ }
363
+
357
364
358
365
private class MethodValueRef implements ValueRef {
359
366
0 commit comments