--- a/langtools/test/tools/javac/TryWithResources/TwrForVariable1.java Tue Dec 08 21:02:07 2015 +0100
+++ b/langtools/test/tools/javac/TryWithResources/TwrForVariable1.java Wed Dec 09 14:26:56 2015 +0100
@@ -37,6 +37,49 @@
}
assertCloseCount(6);
+
+ // null test cases
+ TwrForVariable1 n = null;
+
+ try (n) {
+ }
+ try (n) {
+ throw new Exception();
+ } catch (Exception e) {
+ }
+
+ assertCloseCount(6);
+
+ // initialization exception
+ TwrForVariable1 i1 = new TwrForVariable1();
+ try (i1; TwrForVariable1 i2 = new TwrForVariable1(true)) {
+ } catch (Exception e) {
+ }
+
+ assertCloseCount(7);
+
+ // multiple closures
+ TwrForVariable1 m1 = new TwrForVariable1();
+ try (m1; TwrForVariable1 m2 = m1; TwrForVariable1 m3 = m2;) {
+ }
+
+ assertCloseCount(10);
+
+ // aliasing of variables keeps equality (bugs 6911256 6964740)
+ TwrForVariable1 a1 = new TwrForVariable1();
+ try (a1; TwrForVariable1 a2 = a1;) {
+ if (a2 != a2)
+ throw new RuntimeException("Unexpected inequality.");
+ }
+
+ assertCloseCount(12);
+
+ // anonymous class implementing AutoCloseable as variable in twr
+ AutoCloseable a = new AutoCloseable() {
+ public void close() { };
+ };
+ try (a) {
+ } catch (Exception e) {}
}
static void assertCloseCount(int expectedCloseCount) {
@@ -66,4 +109,13 @@
closeCount++;
}
}
+
+ public TwrForVariable1(boolean throwException) {
+ if (throwException)
+ throw new RuntimeException("Initialization exception");
+ }
+
+ public TwrForVariable1() {
+ this(false);
+ }
}