Improve 080-oom-throw-with-finalizer.
Avoid potential OOME that may be thrown during System.out.println or
System.runFinalization.
Bug: 19677738
Change-Id: I60c678000e965899cc876e746e72dc9cc0c6ebf9
diff --git a/test/080-oom-throw-with-finalizer/src/Main.java b/test/080-oom-throw-with-finalizer/src/Main.java
index 57e9721..61a1b75 100644
--- a/test/080-oom-throw-with-finalizer/src/Main.java
+++ b/test/080-oom-throw-with-finalizer/src/Main.java
@@ -59,13 +59,22 @@
// Keep holder alive to make instance OOM happen faster.
holder = new char[128 * 1024][];
if (!triggerArrayOOM(holder)) {
+ // The test failed here. To avoid potential OOME during println,
+ // make holder unreachable.
+ holder = null;
System.out.println("NEW_ARRAY did not throw OOME");
}
if (!triggerInstanceFinalizerOOM()) {
+ // The test failed here. To avoid potential OOME during println,
+ // make holder unreachable.
+ holder = null;
System.out.println("NEW_INSTANCE (finalize) did not throw OOME");
}
+ // Make holder unreachable here so that the Sentinel
+ // allocation in runFinalization() won't fail.
+ holder = null;
System.runFinalization();
}
}