Reproduce issue 387258081
Reflective identification of instantiation fails to keep the
instantiated class.
Bug: b/387258081
Change-Id: I79a6f418564beb6fbd2b0f70536ec8d6cee4f1a0
diff --git a/src/test/java/com/android/tools/r8/shaking/reflection/ReflectiveNewInstanceTest.java b/src/test/java/com/android/tools/r8/shaking/reflection/ReflectiveNewInstanceTest.java
index 301c06a..cdb8f78 100644
--- a/src/test/java/com/android/tools/r8/shaking/reflection/ReflectiveNewInstanceTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/reflection/ReflectiveNewInstanceTest.java
@@ -39,7 +39,8 @@
@Test
public void test() throws Exception {
String expectedOutput =
- StringUtils.lines("Success", "Success", "Success", "Success", "Success");
+ StringUtils.lines(
+ "Success", "Success", "Success", "Success", "Success", "Success", "Success");
if (parameters.isCfRuntime()) {
testForJvm(parameters)
@@ -132,6 +133,25 @@
} catch (Exception e) {
System.out.println("Fail");
}
+
+ try {
+ UninitializedMemberUsed o = UninitializedMemberUsed.class.newInstance();
+ if (!o.b) {
+ o.a();
+ }
+ } catch (Exception e) {
+ System.out.println("Fail");
+ }
+
+ try {
+ UninitializedMemberUsed o =
+ UninitializedMemberUsed.class.getDeclaredConstructor().newInstance();
+ if (!o.b) {
+ o.a();
+ }
+ } catch (Exception e) {
+ System.out.println("Fail");
+ }
}
}
@@ -153,4 +173,13 @@
@KeepUnusedArguments
public D(Object arg1, String arg2) {}
}
+
+ public static class UninitializedMemberUsed {
+ boolean b;
+
+ public void a() {
+ this.b = true;
+ System.out.println("Success");
+ }
+ }
}