From f9284c694319586038bbe92ad66caa037bc3db00 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 8 Nov 2022 15:56:39 +0000 Subject: Bug 581012 Fix some warnings with SpotBugs More fixes Change-Id: I594d3ea52da91597813460bc11fa0afbbbb642d4 --- .../src/org/eclipse/mat/query/refined/Filter.java | 6 +++--- .../mat/query/refined/RefinedStructuredResult.java | 25 +++++++++++++++++++++- .../eclipse/mat/report/internal/CSVOutputter.java | 5 ++--- .../eclipse/mat/report/internal/TextOutputter.java | 5 ++--- plugins/org.eclipse.mat.tests/.classpath | 6 +++++- .../.settings/org.eclipse.jdt.core.prefs | 11 ++++++---- plugins/org.eclipse.mat.tests/META-INF/MANIFEST.MF | 2 +- .../regression/comparator/BinaryComparator.java | 22 ++++--------------- .../tests/regression/comparator/CSVComparator.java | 4 ++-- .../mat/tests/snapshot/MultipleSnapshots.java | 6 ++++-- .../eclipse/mat/tests/snapshot/QueriesTest.java | 7 +++--- 11 files changed, 57 insertions(+), 42 deletions(-) diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/Filter.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/Filter.java index f7de1f94..39704e34 100644 --- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/Filter.java +++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/Filter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2020 SAP AG and IBM Corporation. + * Copyright (c) 2008, 2022 SAP AG and IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -511,11 +511,11 @@ public abstract class Filter /// otherwise report the failure from the percent formatter if (nresult != null) { - if (p2.getIndex() < string.length() && string.charAt(p2.getIndex()) == '%' && nresult instanceof Number) + if (p2.getIndex() < string.length() && string.charAt(p2.getIndex()) == '%') { // Old way with trailing % (no space) // - some locale formatters just parse "12.34 %" with a non-breaking space - nresult = ((Number)nresult).doubleValue() / 100; + nresult = nresult.doubleValue() / 100; p2.setIndex(p2.getIndex() + 1); } pos = p2; diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/RefinedStructuredResult.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/RefinedStructuredResult.java index 21cbf319..921b4f32 100644 --- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/RefinedStructuredResult.java +++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/RefinedStructuredResult.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2020 SAP AG and IBM Corporation. + * Copyright (c) 2008, 2022 SAP AG and IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Objects; import org.eclipse.mat.SnapshotException; import org.eclipse.mat.collect.ArrayInt; @@ -104,6 +105,28 @@ public abstract class RefinedStructuredResult implements IStructuredResult, // { this.filteredCount = filteredCount; } + + @Override + public int hashCode() + { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(filteredCount); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + FilteredList other = (FilteredList) obj; + return filteredCount == other.filteredCount; + } } /* package */static final class NaturalComparator implements Comparator diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/CSVOutputter.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/CSVOutputter.java index 3ce39c52..5bc445ec 100644 --- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/CSVOutputter.java +++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/CSVOutputter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2021 SAP AG and IBM Corporation + * Copyright (c) 2008, 2022 SAP AG and IBM Corporation * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -22,13 +22,12 @@ import org.eclipse.mat.query.IResult; import org.eclipse.mat.query.IResultTable; import org.eclipse.mat.query.IResultTree; import org.eclipse.mat.query.refined.Filter; -import org.eclipse.mat.report.IOutputter; import org.eclipse.mat.report.Renderer; import com.ibm.icu.text.DecimalFormatSymbols; @Renderer(target = "csv", result = { IResultTree.class, IResultTable.class }) -public class CSVOutputter extends OutputterBase implements IOutputter +public class CSVOutputter extends OutputterBase { private static final char SEPARATOR = new DecimalFormatSymbols().getDecimalSeparator() == ',' ? ';' : ','; diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/TextOutputter.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/TextOutputter.java index 7eac64eb..0e8631a7 100644 --- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/TextOutputter.java +++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/TextOutputter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 SAP AG and IBM Corporation + * Copyright (c) 2021, 2022 SAP AG and IBM Corporation * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -30,13 +30,12 @@ import org.eclipse.mat.query.refined.Filter; import org.eclipse.mat.query.refined.RefinedStructuredResult; import org.eclipse.mat.query.refined.TotalsRow; import org.eclipse.mat.query.results.TextResult; -import org.eclipse.mat.report.IOutputter; import org.eclipse.mat.report.Renderer; import org.eclipse.mat.util.MessageUtil; import org.eclipse.mat.util.VoidProgressListener; @Renderer(target = "txt", result = { IResultTree.class, IResultTable.class, TextResult.class, IResultPie.class }) -public class TextOutputter extends OutputterBase implements IOutputter +public class TextOutputter extends OutputterBase { @Override public void process(Context context, IResult result, Writer writer) throws IOException diff --git a/plugins/org.eclipse.mat.tests/.classpath b/plugins/org.eclipse.mat.tests/.classpath index 45f024e8..81065bd1 100644 --- a/plugins/org.eclipse.mat.tests/.classpath +++ b/plugins/org.eclipse.mat.tests/.classpath @@ -1,7 +1,11 @@ - + + + + + diff --git a/plugins/org.eclipse.mat.tests/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.mat.tests/.settings/org.eclipse.jdt.core.prefs index 2df07b5d..c59d0c6a 100644 --- a/plugins/org.eclipse.mat.tests/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/org.eclipse.mat.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,15 @@ -#Mon Jun 23 11:10:43 CEST 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/org.eclipse.mat.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.mat.tests/META-INF/MANIFEST.MF index 2ae27d3b..c008e216 100644 --- a/plugins/org.eclipse.mat.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.mat.tests/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: Memory Analyzer Tests Bundle-SymbolicName: org.eclipse.mat.tests;singleton:=true Bundle-Version: 1.13.0.qualifier -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.mat.api;bundle-version="1.0.0", org.eclipse.mat.parser;bundle-version="1.13.0", org.eclipse.core.runtime;bundle-version="3.4", diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/BinaryComparator.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/BinaryComparator.java index a70f91c7..cb57e769 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/BinaryComparator.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/BinaryComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 SAP AG. + * Copyright (c) 2008, 2022 SAP AG and IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -37,8 +37,6 @@ public class BinaryComparator implements IComparator List differences = new ArrayList(); - InputStream baselineStream = null; - InputStream testStream = null; if (baseline.length() != testFile.length()) { String errorMessage = MessageUtil.format( @@ -49,10 +47,10 @@ public class BinaryComparator implements IComparator return differences; } - try + try ( + InputStream baselineStream = new FileInputStream(baseline); + InputStream testStream = new FileInputStream(testFile);) { - baselineStream = new FileInputStream(baseline); - testStream = new FileInputStream(testFile); if (inputStreamEquals(testName, baselineStream, testStream)) { @@ -72,18 +70,6 @@ public class BinaryComparator implements IComparator .getMessage())); return null; } - finally - { - try - { - if (baselineStream != null) - baselineStream.close(); - if (testStream != null) - testStream.close(); - } - catch (Exception ex) - {} - } } private boolean inputStreamEquals(String testName, InputStream baselineStream, InputStream testStream) diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/CSVComparator.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/CSVComparator.java index 7ee7734a..d163d314 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/CSVComparator.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/regression/comparator/CSVComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008,2020 SAP AG and IBM Corporation. + * Copyright (c) 2008,2022 SAP AG and IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -54,7 +54,7 @@ public class CSVComparator implements IComparator { if (!(baseLine).equals(testLine = testFileReader.readLine())) { - differences.add(new Difference(Integer.valueOf(lineNumber).toString(), baseLine, testLine)); + differences.add(new Difference(String.valueOf(lineNumber), baseLine, testLine)); } if (differences.size() == 10) // add only first 10 differences break; diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/MultipleSnapshots.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/MultipleSnapshots.java index 894d6503..87e83f2a 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/MultipleSnapshots.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/MultipleSnapshots.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation. + * Copyright (c) 2013, 2022 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.mat.tests.snapshot; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -42,7 +44,7 @@ public class MultipleSnapshots catch (RuntimeException e) { Throwable f = e.getCause(); - assertTrue(f instanceof MultipleSnapshotsException); + assertThat(f, instanceOf(MultipleSnapshotsException.class)); MultipleSnapshotsException s = (MultipleSnapshotsException)f; assertEquals(2, s.getRuntimes().size()); Listctxs = s.getRuntimes(); diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java index 054cf1f2..2c187ce0 100644 --- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java +++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2021 IBM Corporation. + * Copyright (c) 2011, 2022 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,8 +13,8 @@ package org.eclipse.mat.tests.snapshot; -import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.AllOf.allOf; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsInstanceOf.instanceOf; @@ -35,7 +35,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Locale; @@ -208,7 +207,7 @@ public class QueriesTest Object row = table.getRow(i); Object val = table.getColumnValue(row, 0); // Check no non-numeric item - assertTrue(val instanceof Number); + assertThat(val, instanceOf(Number.class)); } } -- cgit v1.2.3