Skip to content

Commit

Permalink
* adds logic to skip bridged synthetic JVM methods added by compiler …
Browse files Browse the repository at this point in the history
…to handle overridden covariant return type methods. This fixes compiler exception while compiling `NWTxtRecord` class: (MobiVM#422)

java.lang.IllegalArgumentException: @bridge annotated method <org.robovm.apple.network.NWTxtRecord: org.robovm.apple.foundation.NSObject copy()> must be native
	at org.robovm.compiler.BridgeMethodCompiler.validateBridgeMethod(BridgeMethodCompiler.java:87)
	at org.robovm.compiler.BridgeMethodCompiler.doCompile(BridgeMethodCompiler.java:233)
  • Loading branch information
dkimitsa committed Apr 9, 2020
1 parent 4ea47f4 commit 694a246
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,13 @@ private void compile(Clazz clazz, OutputStream out) throws IOException {
String name = method.getName();
Function function = null;
if (hasBridgeAnnotation(method)) {
function = bridgeMethod(method);
// javac generates JVM synthetic bridge methods for covariant return
// and copies @Bridge annotations as well. Don't try to compile bridge methods
// as these are not a subject for RoboVM bridge compiler and it will fail on them
if (!isJvmSyntheticBridgeMethod(method))
function = bridgeMethod(method);
else
function = method(method);
} else if (hasGlobalValueAnnotation(method)) {
function = globalValueMethod(method);
} else if (isStruct(sootClass) && ("_sizeOf".equals(name)
Expand Down Expand Up @@ -1040,6 +1046,16 @@ private void compile(Clazz clazz, OutputStream out) throws IOException {
clazz.saveClazzInfo();
}

private boolean isJvmSyntheticBridgeMethod(SootMethod method) {
final int BRIDGE = 0x00000040;
final int SYNTHETIC = 0x00001000;

return !method.isAbstract() &&
!method.isNative() &&
(method.getModifiers() & BRIDGE) == BRIDGE &&
(method.getModifiers() & SYNTHETIC) == SYNTHETIC;
}

private static void addClassDependencyIfNeeded(Clazz clazz, soot.Type type, boolean weak) {
if (type instanceof RefLikeType) {
addClassDependencyIfNeeded(clazz, getDescriptor(type), weak);
Expand Down Expand Up @@ -1495,7 +1511,7 @@ private StructureConstant createClassInfoStruct() {
body.add(linetableGlobal.ref());
}
}
if (hasBridgeAnnotation(m)) {
if (hasBridgeAnnotation(m) && !isJvmSyntheticBridgeMethod(m)) {
if (!readBooleanElem(getAnnotation(m, BRIDGE), "dynamic", false)) {
body.add(new GlobalRef(Symbols.bridgePtrSymbol(m), I8_PTR));
} else {
Expand Down

0 comments on commit 694a246

Please sign in to comment.