Skip to content

Instantly share code, notes, and snippets.

@justinjhendrick
Created August 9, 2017 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinjhendrick/b570fea63df6b7b00d9a1c406cb50fc5 to your computer and use it in GitHub Desktop.
Save justinjhendrick/b570fea63df6b7b00d9a1c406cb50fc5 to your computer and use it in GitHub Desktop.
// java.lang.VerifyError when returning an array of an interface
// Dalvik error message
// W/dalvikvm( 8228): VFY: returning [Ljava/lang/Object; (cl=0x0), declared [Ltest/Empty; (cl=0x40d5f510)
// W/dalvikvm( 8228): VFY: rejecting opcode 0x11 at 0x000f
// W/dalvikvm( 8228): VFY: rejected Ltest/Counter;.two_returns ()[Ltest/Empty;
// W/dalvikvm( 8228): Verifier rejected class Ltest/Counter;
// ART error message
// 7149 7149 E AndroidRuntime: java.lang.VerifyError: Verifier rejected class test.Counter: test.Empty[] test.Counter.two_returns() failed to verify: test.Empty[] test.Counter.two_returns(): [0xF] returning 'Reference: java.lang.Object[]', but expected from declaration 'Reference: test.Empty[]' (declaration of 'test.Counter' appears in /data/app/test-1/base.apk)
package test;
import android.app.Activity;
import android.os.Bundle;
interface Empty {
}
class A implements Empty {
}
class B implements Empty {
}
public class Counter extends Activity {
// throws a VerifyError
public Empty[] two_returns() {
if (Math.random() > .5) {
return new A[1];
} else {
return new B[1];
}
}
// Does not throw a VerifyError
public Empty[] one_return_A() {
return new A[1];
}
// Does not throw a VerifyError
public Empty[] one_return_B() {
return new B[1];
}
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println(two_returns());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment