Add regression test for b/151964517
Bug: 151964517
Change-Id: I39785548f4ae11d783bff576123d718e6cee83d0
diff --git a/src/test/java/com/android/tools/r8/regress/b151964517/ConstStringWithMonitorTest.java b/src/test/java/com/android/tools/r8/regress/b151964517/ConstStringWithMonitorTest.java
new file mode 100644
index 0000000..7c8aa34
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/regress/b151964517/ConstStringWithMonitorTest.java
@@ -0,0 +1,74 @@
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.regress.b151964517;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class ConstStringWithMonitorTest extends TestBase {
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withDexRuntimes().build();
+ }
+
+ public ConstStringWithMonitorTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void regress() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(ConstStringWithMonitorTest.class)
+ .noMinification()
+ .allowAccessModification()
+ .addKeepMainRule(TestClass.class)
+ .compile()
+ .runDex2Oat(parameters.getRuntime());
+ // TODO(b/151964517): Should pass verification with assertNoVerificationErrors()
+ }
+
+ public static class TestClass {
+ public static void main(String[] args) {
+ try {
+ System.out.println(FooBar.tryIt());
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static class Value {
+ public final String value;
+
+ public Value(String value) {
+ this.value = value;
+ }
+ }
+
+ public static class FooBar {
+ private static Object mLock = new Object();
+
+ public static String tryIt() {
+ Value value = synchronizedMethod("foobar");
+ return value.value;
+ }
+
+ private static Value synchronizedMethod(String s) {
+ synchronized (mLock) {
+ if (System.currentTimeMillis() < 2) {
+ s.length();
+ throw new IllegalStateException("wrong" + s);
+ }
+ return new Value(s);
+ }
+ }
+ }
+}