diff --git a/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/Pass1Parser.java b/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/Pass1Parser.java index 7285f6138..ee8b287ea 100644 --- a/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/Pass1Parser.java +++ b/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/Pass1Parser.java @@ -680,9 +680,9 @@ private void readClassDump(long segmentStartPos) throws IOException statics[si++] = new Field("", Type.OBJECT, signersId == 0 ? null : new ObjectReference(null, signersId)); //$NON-NLS-1$ statics[si++] = new Field("", Type.OBJECT, protectionDomainId == 0 ? null : new ObjectReference(null, protectionDomainId)); //$NON-NLS-1$ if (reserved1Id != 0) - statics[si++] = new Field("", Type.OBJECT, reserved1Id == 0 ? null : new ObjectReference(null, reserved1Id)); //$NON-NLS-1$ + statics[si++] = new Field("", Type.OBJECT, new ObjectReference(null, reserved1Id)); //$NON-NLS-1$ if (reserved2Id != 0) - statics[si++] = new Field("", Type.OBJECT, reserved2Id == 0 ? null : new ObjectReference(null, reserved2Id)); //$NON-NLS-1$ + statics[si++] = new Field("", Type.OBJECT, new ObjectReference(null, reserved2Id)); //$NON-NLS-1$ Field all[] = new Field[statics.length + constantPool.length]; System.arraycopy(statics, 0, all, 0, statics.length); System.arraycopy(constantPool, 0, all, statics.length, constantPool.length); diff --git a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/internal/snapshot/ObjectMarker.java b/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/internal/snapshot/ObjectMarker.java index 796923121..d50f680f3 100644 --- a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/internal/snapshot/ObjectMarker.java +++ b/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/internal/snapshot/ObjectMarker.java @@ -117,7 +117,7 @@ public long markMultiThreadedInner(int threads) throws InterruptedException ForkJoinPool pool = new ForkJoinPool(threads); try { - ObjectMarkerRootCC root = new ObjectMarkerRootCC(null, claimedRoots, bitField, LEVELS_RUN_INLINE, count); + ObjectMarkerRootCC root = new ObjectMarkerRootCC(claimedRoots, bitField, LEVELS_RUN_INLINE, count); // blocks until all work is done pool.invoke(root); } @@ -141,8 +141,8 @@ final class ObjectMarkerRootCC extends CountedCompleter { final int levelsInline; final LongAdder count; - ObjectMarkerRootCC(CountedCompleter parent, int[] roots, ConcurrentBitField visited, int levelsInline, LongAdder count) { - super(parent); + ObjectMarkerRootCC(int[] roots, ConcurrentBitField visited, int levelsInline, LongAdder count) { + super(); this.roots = roots; this.visited = visited; this.levelsInline = levelsInline; diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java index 00959559b..35bac2b4e 100644 --- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java +++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java @@ -192,6 +192,9 @@ private static final Spec read(InputStream input, Bundle bundle, Object source) parserFactory.setNamespaceAware(true); // Add schema validation URL url = ReportPlugin.getDefault().getBundle().getResource("schema/report.xsd"); //$NON-NLS-1$ + if (url == null) { + throw new IOException("Schema resource not found in bundle: schema/report.xsd"); //$NON-NLS-1$ + } SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(url); parserFactory.setSchema(schema); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/CreateCollectionDump.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/CreateCollectionDump.java index 085d06a43..62dc12d27 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/CreateCollectionDump.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/CreateCollectionDump.java @@ -174,10 +174,9 @@ public static void main(String[] args) throws Exception System.out.println("Acquire Heap Dump NOW (then press any key to terminate program)"); int c = System.in.read(); // Control-break causes read to return early, so try again for another - // key to wait - // for the dump to complete + // key to wait for the dump to complete if (c == -1) - c = System.in.read(); + System.in.read(); cd.print(); } diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java index 35e36b8e8..fe711dc57 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java @@ -508,7 +508,7 @@ void fillAdders() doubleAdderValues = new DoubleAdder[2]; doubleAdderValues[0] = new DoubleAdder(); - doubleAdderValues[0].add(3.14159); + doubleAdderValues[0].add(Math.PI); doubleAdderValues[1] = new DoubleAdder(); } @@ -551,15 +551,15 @@ void checkDoubleAdderResolver(ISnapshot snapshot) throws SnapshotException IResult result = query.execute(new VoidProgressListener()); assertNotNull(result); IResultTable table = (IResultTable) result; - boolean found3_14159 = false; + boolean found_pi = false; for (int i = 0; i < table.getRowCount(); ++i) { Object row = table.getRow(i); String val = (String) table.getColumnValue(row, 0); - if (Double.toString(3.14159).equals(val)) - found3_14159 = true; + if (Double.toString(Math.PI).equals(val)) + found_pi = true; } - assertTrue("DoubleAdder with sum 3.14159 should be resolved", found3_14159); //$NON-NLS-1$ + assertTrue("DoubleAdder with sum 3.14159 should be resolved", found_pi); //$NON-NLS-1$ } BigDecimal values[]; diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayIntTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayIntTest.java index 74e68730e..def02dc70 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayIntTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayIntTest.java @@ -25,6 +25,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.ArrayInt; import org.eclipse.mat.collect.IteratorInt; @@ -47,7 +48,7 @@ public class ArrayIntTest */ @Test public void testArrayInt0() { - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); for (int i = 0; i < COUNT; ++i) { int t = 0; ArrayInt ss = new ArrayInt(r.nextInt(INITIAL_SIZE)); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayLongTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayLongTest.java index bb401ae53..15d6b912a 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayLongTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/ArrayLongTest.java @@ -26,6 +26,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.ArrayLong; import org.eclipse.mat.collect.IteratorLong; @@ -48,7 +49,7 @@ public class ArrayLongTest */ @Test public void testArrayLong0() { - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); for (int i = 0; i < COUNT; ++i) { int t = 0; ArrayLong ss = new ArrayLong(r.nextInt(INITIAL_SIZE)); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/CompressedArraysTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/CompressedArraysTest.java index ee041ff6c..9ff912a67 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/CompressedArraysTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/CompressedArraysTest.java @@ -16,6 +16,7 @@ import static org.junit.Assert.assertEquals; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.ArrayIntCompressed; import org.eclipse.mat.collect.ArrayLongCompressed; @@ -28,7 +29,7 @@ public class CompressedArraysTest @Test public void testIntArrayCompressed() { - Random rand = new Random(SEED); + Random rand = ThreadLocalRandom.current(); int INTS = 1024; int TESTS = 10; for (int i = 1; i <= INTS; i++) @@ -55,7 +56,7 @@ public void testIntArrayCompressed() @Test public void testLongArrayCompressed() { - Random rand = new Random(SEED); + Random rand = ThreadLocalRandom.current(); int LONGS = 1024; int TESTS = 10; for (int i = 1; i <= LONGS; i++) @@ -85,7 +86,7 @@ public void testLongArrayCompressed() @Test public void testIntAndLongArrayCompressed() { - Random rand = new Random(SEED); + Random rand = ThreadLocalRandom.current(); int INTS = 1024; int TESTS = 10; for (int i = 1; i <= INTS; i++) @@ -116,7 +117,7 @@ public void testIntAndLongArrayCompressed() @Test public void testLongAndIntArrayCompressed() { - Random rand = new Random(SEED); + Random rand = ThreadLocalRandom.current(); int INTS = 1024; int TESTS = 10; for (int i = 1; i <= INTS; i++) @@ -147,7 +148,7 @@ public void testLongAndIntArrayCompressed() @Test public void testIntArrayCompressedOverwrite() { - Random rand = new Random(SEED); + Random rand = ThreadLocalRandom.current(); int INTS = 100; for (int i = 1; i <= INTS; i++) { @@ -218,7 +219,7 @@ public void testIntArrayCompressedOverwrite() @Test public void testLongArrayCompressedOverwrite() { - Random rand = new Random(SEED); + Random rand = ThreadLocalRandom.current(); int LONGS = 100; for (int i = 1; i <= LONGS; i++) { diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/QueueIntTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/QueueIntTest.java index b64891104..c798010b5 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/QueueIntTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/QueueIntTest.java @@ -25,6 +25,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.QueueInt; import org.eclipse.mat.collect.IteratorInt; @@ -47,7 +48,7 @@ public class QueueIntTest */ @Test public void testQueueInt0() { - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); for (int i = 0; i < COUNT; ++i) { int t = 0; QueueInt ss = new QueueInt(r.nextInt(INITIAL_SIZE)); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetIntTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetIntTest.java index 92c97e927..b73d023e8 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetIntTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetIntTest.java @@ -25,6 +25,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.IteratorInt; import org.eclipse.mat.collect.SetInt; @@ -47,7 +48,7 @@ public class SetIntTest */ @Test public void testSetInt0() { - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); for (int i = 0; i < COUNT; ++i) { int t = 0; SetInt ss = new SetInt(r.nextInt(INITIAL_SIZE)); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetLongTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetLongTest.java index 2c76465d5..67dfeffb6 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetLongTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SetLongTest.java @@ -25,6 +25,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.IteratorLong; import org.eclipse.mat.collect.SetLong; @@ -47,7 +48,7 @@ public class SetLongTest */ @Test public void testSetLong0() { - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); for (int i = 0; i < COUNT; ++i) { int t = 0; SetLong ss = new SetLong(r.nextInt(INITIAL_SIZE)); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SortTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SortTest.java index 988021d67..e6f7a7642 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SortTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/collect/SortTest.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.collect.ArrayUtils; import org.junit.Test; @@ -55,7 +56,7 @@ public void testSort() { // Generate random data int n = longTest ? 29792349 : SHORTTEST; - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); int[] key0 = new int[n]; int[] key = new int[n]; int[] value = new int[n]; @@ -198,7 +199,7 @@ public void testSort5() { // Generate random data int n = longTest ? 29792349 : SHORTTEST; - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); int k = n; int[] key0 = new int[n]; int[] key = new int[n]; @@ -223,7 +224,7 @@ public void testSort5() public void testSortDesc() { int n = longTest ? 29792349 : SHORTTEST; - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); long[] key0 = new long[n]; long[] key = new long[n]; int[] value = new int[n]; @@ -363,7 +364,7 @@ public void testSortDesc4() public void testSortDesc5() { int n = longTest ? 29792349 : SHORTTEST; - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); long[] key0 = new long[n]; long[] key = new long[n]; int[] value = new int[n]; diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/GzipTests.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/GzipTests.java index 8a634c643..87fb80977 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/GzipTests.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/GzipTests.java @@ -28,11 +28,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import java.util.function.Supplier; import java.util.zip.Deflater; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.eclipse.mat.hprof.ChunkedGZIPRandomAccessFile; import org.eclipse.mat.hprof.GZIPInputStream2; import org.eclipse.mat.hprof.SeekableStream; @@ -70,6 +72,7 @@ public GzipTests(int comp) this.comp = comp; } + @SuppressFBWarnings(value = "DMI_RANDOM_USED_ONLY_ONCE", justification = "Random is used with fixed seeds to assert test data consistency") static byte[] randomText(int size) { Random rn = new Random(1); @@ -197,7 +200,7 @@ public void test1() throws IOException try (ByteArrayInputStream bis = new ByteArrayInputStream(bo, 0, bol)) { try (InflaterInputStream inf = new InflaterInputStream(bis, false)) { - Random r = new Random(1); + Random r = ThreadLocalRandom.current(); byte bo2[] = new byte[inputLen]; int MAXMARK = 32211; int mark = -1; @@ -293,6 +296,7 @@ public InputStream get() checkSeekableStream(b, ss); } + @SuppressFBWarnings(value = "DMI_RANDOM_USED_ONLY_ONCE", justification = "Random is used with fixed seeds to assert test data consistency") private void checkSeekableStream(byte[] b, SeekableStream ss) throws IOException { int inputLen = b.length; diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex.java index 42d556528..9196a55e2 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.mat.parser.index.IIndexReader.IOne2ManyIndex; import org.eclipse.mat.parser.index.IIndexReader.IOne2ManyObjectsIndex; @@ -212,7 +213,7 @@ public void storeKey(int index, Serializable key) public void testLong() throws IOException { assumeTrue((long) M * N < MAXELEMENTS); - Random r = new Random(); + Random r = ThreadLocalRandom.current(); long ii[][] = new long[P + 1][]; for (int p = 0; p < P + 1; p++) { diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex1to1.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex1to1.java index 6d4faf4f8..30d7e6fb2 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex1to1.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/parser/TestIndex1to1.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.Random; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.eclipse.mat.collect.IteratorInt; import org.eclipse.mat.collect.IteratorLong; import org.eclipse.mat.parser.index.IIndexReader; @@ -38,7 +39,7 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; - +@SuppressFBWarnings(value = "DMI_RANDOM_USED_ONLY_ONCE", justification = "Random is used with fixed seeds to assert test data consistency") @RunWith(value = Parameterized.class) public class TestIndex1to1 {