Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e51562d9 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Make sure to remove final from nested classes too

Nested classes' access flags are actually stored in "inner_classes"
fields.

Fix: 416773120
Bug: 415310569
Flag: EXEMPT host test change only

Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh -s
Test: atest CarLibHostUnitTest:android.car.media.CarAudioManagerUnitTest#switchAudioZoneToConfig_withNullConfig_fails

Change-Id: Id5a7d49495329eadffc3ba59be23666970b92f05
parent 869ac441
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.platform.test.ravenwood.RavenwoodRule;

import org.junit.Rule;
@@ -66,4 +67,67 @@ public class RavenwoodMockitoTest {

        assertThat(object.readInt()).isEqualTo(123);
    }

    public static final class MyFinalClass {
        public int getValue() {
            return 1;
        }
    }

    public static final class MyParcelable implements Parcelable {
        private final int mValue;

        public MyParcelable(int value) {
            mValue = value;
        }

        private MyParcelable(Parcel src) {
            mValue = src.readInt();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mValue);
        }

        public int getValue() {
            return mValue;
        }

        public static final Parcelable.Creator<MyParcelable> CREATOR =
                new Parcelable.Creator<>() {
                    public MyParcelable createFromParcel(Parcel in) {
                        return new MyParcelable(in);
                    }

                    public MyParcelable[] newArray(int size) {
                        return new MyParcelable[size];
                    }
                };
    }

    @Test
    public void testMockLocalFinalClass() {
        var p1 = mock(MyFinalClass.class);

        when(p1.getValue()).thenReturn(42);
        assertThat(p1.getValue()).isEqualTo(42);
    }

    @Test
    public void testMockLocalFinalParcelableClass() {
        // First, test the non-mock version, just in case.
        var p1 = new MyParcelable(1);
        assertThat(p1.getValue()).isEqualTo(1);

        var p2 = mock(MyParcelable.class);

        when(p2.getValue()).thenReturn(42);
        assertThat(p2.getValue()).isEqualTo(42);
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -99,6 +99,15 @@ class ImplGeneratingAdapter(
        return access
    }

    override fun visitInnerClass(
        name: String?,
        outerName: String?,
        innerName: String?,
        access: Int,
    ) {
        super.visitInnerClass(name, outerName, innerName, maybeRemoveFinalFromClass(access))
    }

    override fun visit(
        version: Int,
        origAccess: Int,
+3 −3
Original line number Diff line number Diff line
@@ -1774,7 +1774,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;            // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -1963,7 +1963,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;           // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -2271,7 +2271,7 @@ Constant pool:
InnerClasses:
  public static #x= #x of #x;           // ConstructorTester=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static #x= #x of #x;            // ReplaceTo=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ReplaceTo of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkMethodCallReplace.java"
RuntimeVisibleAnnotations:
  x: #x()
+3 −3
Original line number Diff line number Diff line
@@ -2142,7 +2142,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;            // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -2374,7 +2374,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;           // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -2767,7 +2767,7 @@ Constant pool:
InnerClasses:
  public static #x= #x of #x;           // ConstructorTester=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static #x= #x of #x;           // ReplaceTo=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ReplaceTo of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkMethodCallReplace.java"
RuntimeVisibleAnnotations:
  x: #x()
+3 −3
Original line number Diff line number Diff line
@@ -1725,7 +1725,7 @@ BootstrapMethods:
      #x ()Ljava/lang/Integer;
InnerClasses:
  public static #x= #x of #x;          // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
## Class: com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas.class
  Compiled from "TinyFrameworkLambdas.java"
public class com.android.hoststubgen.test.tinyframework.TinyFrameworkLambdas
@@ -1882,7 +1882,7 @@ BootstrapMethods:
      #x ()Ljava/lang/Integer;
InnerClasses:
  public static #x= #x of #x;          // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
## Class: com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester.class
  Compiled from "TinyFrameworkMethodCallReplace.java"
public class com.android.hoststubgen.test.tinyframework.TinyFrameworkMethodCallReplace$ConstructorTester
@@ -2125,7 +2125,7 @@ BootstrapMethods:
InnerClasses:
  public static #x= #x of #x;          // ConstructorTester=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static #x= #x of #x;          // ReplaceTo=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ReplaceTo of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static final #x= #x of #x;   // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;   // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
## Class: com/android/hoststubgen/test/tinyframework/TinyFrameworkNative.class
  Compiled from "TinyFrameworkNative.java"
public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative
Loading