Skip to content

Commit

Permalink
Disable assertion on Java 9+
Browse files Browse the repository at this point in the history
  • Loading branch information
batmat committed Mar 7, 2019
1 parent b4de964 commit fcd5d43
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/jvnet/hudson/test/MemoryAssert.java
Expand Up @@ -40,6 +40,8 @@
import javax.swing.BoundedRangeModel;
import jenkins.model.Jenkins;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;

import org.netbeans.insane.impl.LiveEngine;
import org.netbeans.insane.live.LiveReferences;
import org.netbeans.insane.live.Path;
Expand Down Expand Up @@ -146,13 +148,16 @@ public static void assertGC(WeakReference<?> reference) {
}

/**
* <strong>Assumes Java runtime is &le; Java 8. I.e. tests will be skipped if Java 9+</strong>
* Forces GC by causing an OOM and then verifies the given {@link WeakReference} has been garbage collected.
* @param reference object used to verify garbage collection.
* @param allowSoft if true, pass even if {@link SoftReference}s apparently needed to be cleared by forcing an {@link OutOfMemoryError};
* if false, fail in such a case (though the failure will be slow)
*/
@SuppressWarnings("DLS_DEAD_LOCAL_STORE_OF_NULL")
public static void assertGC(WeakReference<?> reference, boolean allowSoft) {
// Disabled on Java 9+, because below will call Netbeans Insane Engine, which in turns tries to call setAccessible
assumeTrue(System.getProperty("java.specification.version").startsWith("1."));
assertTrue(true); reference.get(); // preload any needed classes!
System.err.println("Trying to collect " + reference.get() + "…");
Set<Object[]> objects = new HashSet<Object[]>();
Expand Down

0 comments on commit fcd5d43

Please sign in to comment.