Skip to content

Commit

Permalink
Cleanup: remove unnecessary throws declarations from methods (spotbug…
Browse files Browse the repository at this point in the history
…s#3220)

* remove unnecessary throws declarations from methods

* add changelog and spotlessapply
  • Loading branch information
JuditKnoll authored Dec 4, 2024
1 parent 02e82b6 commit 811962e
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
- Use `Collection.isEmpty()` or `String.isEmpty()` to test for emptiness ([#3180](https://github.com/spotbugs/spotbugs/pull/3180), [#3219](https://github.com/spotbugs/spotbugs/pull/3219))
- Use method references instead of lambdas where possible ([#3179](https://github.com/spotbugs/spotbugs/pull/3179))
- Move default clauses to the end of switches ([#3222](https://github.com/spotbugs/spotbugs/pull/3222))
- Remove unnecessary throws declarations ([#3220](https://github.com/spotbugs/spotbugs/pull/3220))

### Changed
- Bump up Java version to 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -118,7 +117,7 @@ protected void doTestMultiQuickfixResolution(IProject project, List<QuickFixTest
checkJavaFiles(project.members());
}

private void checkJavaFiles(IResource[] iResources) throws CoreException, IOException, JavaModelException {
private void checkJavaFiles(IResource[] iResources) throws CoreException, IOException {
for (IResource resource : iResources) {
if (resource instanceof IFile) {
String fileName = resource.getName();
Expand Down
3 changes: 1 addition & 2 deletions eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,10 @@ private static void readBugCollectionAndProject(IProject project, IProgressMonit
* the bug collection
* @param monitor
* progress monitor
* @throws IOException
* @throws CoreException
*/
public static void storeBugCollection(IProject project, final SortedBugCollection bugCollection, IProgressMonitor monitor)
throws IOException, CoreException {
throws CoreException {

// Store the bug collection and findbugs project in the session
project.setSessionProperty(SESSION_PROPERTY_BUG_COLLECTION, bugCollection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ public ISchedulingRule getRule(int kind, Map<String, String> args) {
* @param kind
* kind the kind of build being requested, see
* IncrementalProjectBuilder
* @throws CoreException
*/
private void doBuild(final Map<?, ?> args, final IProgressMonitor monitor, int kind) throws CoreException {
private void doBuild(final Map<?, ?> args, final IProgressMonitor monitor, int kind) {
boolean incremental = (kind == IncrementalProjectBuilder.INCREMENTAL_BUILD
|| kind == IncrementalProjectBuilder.AUTO_BUILD);
IProject project = getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ private void updateBugCollection(Project findBugsProject, Reporter bugReporter,
// props
st.newPoint("storeBugCollection");
FindbugsPlugin.storeBugCollection(project, resultCollection, monitor);
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "Error performing SpotBugs results update");
} catch (CoreException e) {
FindbugsPlugin.getDefault().logException(e, "Error performing SpotBugs results update");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testCloseTwice() {
}

@Test
void awaitTerminationWithoutShutdown() throws InterruptedException {
void awaitTerminationWithoutShutdown() {
ExecutorService executorService = new CurrentThreadExecutorService();
Assertions.assertThrows(IllegalStateException.class, () -> {
executorService.awaitTermination(1, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private File getFindbugsTestCasesFile(String path) {
}

@BeforeEach
void setUp() throws Exception {
void setUp() {
loadFindbugsPlugin();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Subtypes2Test extends FindBugsTestCase {
ObjectType typeParameterString;

@BeforeEach
void setUp() throws Exception {
void setUp() {
typeSerializable = ObjectTypeFactory.getInstance("java.io.Serializable");
typeClonable = ObjectTypeFactory.getInstance("java.lang.Cloneable");
typeObject = ObjectTypeFactory.getInstance(Values.DOTTED_JAVA_LANG_OBJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private Filter readFilterFromXML() throws IOException {
}

@Test
void testPerformAnalysis(SpotBugsRunner spotbugs) throws Exception {
void testPerformAnalysis(SpotBugsRunner spotbugs) {
BugCollection bugCollection = spotbugs.performAnalysis(
Paths.get("../spotbugsTestCases/build/classes/java/main/org/immutables/value/Generated.class"),
Paths.get("../spotbugsTestCases/build/classes/java/main/org/immutables/value/Value.class"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class NotMatcherTest {
private final BugInstance bug = new BugInstance("UUF_UNUSED_FIELD", 0);

@Test
void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() throws Exception {
void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() {
Matcher wrappedMatcher = new TestMatcher(true);
NotMatcher notMatcher = new NotMatcher();
notMatcher.addChild(wrappedMatcher);
Expand All @@ -51,7 +51,7 @@ void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() throws E
}

@Test
void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() throws Exception {
void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() {
Matcher wrappedMatcher = new TestMatcher(false);
NotMatcher notMatcher = new NotMatcher();
notMatcher.addChild(wrappedMatcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void readXML() throws Exception {


@Test
void match() throws Exception {
void match() {
SourceMatcher sm = new SourceMatcher(fileName);

// no source set: test incomplete data
Expand Down Expand Up @@ -131,7 +131,7 @@ void match() throws Exception {
}

@Test
void testRealPathMatchWithRegexpAndProject() throws Exception {
void testRealPathMatchWithRegexpAndProject() {
// add this test class as the bug target
bug.addClass("SourceMatcherTest", null);
ClassAnnotation primaryClass = bug.getPrimaryClass();
Expand All @@ -155,7 +155,7 @@ void testRealPathMatchWithRegexpAndProject() throws Exception {
}

@Test
void testRealPathMatchWithRegexpAndAnalysisContext() throws Exception {
void testRealPathMatchWithRegexpAndAnalysisContext() {
// add this test class as the bug target
bug.addClass("SourceMatcherTest", null);
ClassAnnotation primaryClass = bug.getPrimaryClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import edu.umd.cs.findbugs.DetectorFactoryCollection;
import edu.umd.cs.findbugs.FindBugs2;
import edu.umd.cs.findbugs.Plugin;
import edu.umd.cs.findbugs.PluginException;
import edu.umd.cs.findbugs.PluginLoader;
import edu.umd.cs.findbugs.Priorities;
import edu.umd.cs.findbugs.Project;
Expand Down Expand Up @@ -308,7 +307,7 @@ void testHelpUriAndTags() {
}

@Test
void testExtensions() throws PluginException {
void testExtensions() {
PluginLoader pluginLoader = DetectorFactoryCollection.instance().getCorePlugin().getPluginLoader();
Plugin plugin = new Plugin("pluginId", "version", null, pluginLoader, true, false);
DetectorFactoryCollection dfc = new DetectorFactoryCollection(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ private Plugin constructMinimalPlugin(Document pluginDescriptor, List<Document>
return constructedPlugin;
}

public Document getPluginDescriptor() throws PluginException, PluginDoesntContainMetadataException {
public Document getPluginDescriptor() throws PluginException {
Document pluginDescriptor;

// Read the plugin descriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ SourceRepository makeInMemorySourceRepository(final String url) {
return r;
}

SourceRepository makeJarURLConnectionSourceRepository(final String url) throws MalformedURLException, IOException {
SourceRepository makeJarURLConnectionSourceRepository(final String url) throws IOException {
final File file = File.createTempFile("jar_cache", null);
file.deleteOnExit();
final BlockingSourceRepository r = new BlockingSourceRepository();
Expand All @@ -288,7 +288,7 @@ SourceRepository makeJarURLConnectionSourceRepository(final String url) throws M
* @throws IOException
* @throws MalformedURLException
*/
private InputStream open(final String url) throws IOException, MalformedURLException {
private InputStream open(final String url) throws IOException {
InputStream in = null;
URLConnection connection = new URL(url).openConnection();
if (getProject().isGuiAvaliable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ICodeBaseEntry lookupResource(String resourceName) {
return new DirectoryCodeBaseEntry(this, resourceName);
}

InputStream openFile(String resourceName) throws FileNotFoundException, IOException {
InputStream openFile(String resourceName) throws IOException {
File path = getFullPathOfResource(resourceName);
return new BufferedInputStream(new FileInputStream(path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void visitClassContext(ClassContext classContext) {
* @param classContext
* @param method
*/
private void analyzeMethod(ClassContext classContext, Method method) throws MethodUnprofitableException, CFGBuilderException,
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException,
DataflowAnalysisException {
if (BCELUtil.isSynthetic(method) || (method.getAccessFlags() & Const.ACC_BRIDGE) == Const.ACC_BRIDGE) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void checkQualifier(XMethod xmethod, CFG cfg, TypeQualifierValue<?> type

private void checkDataflow(XMethod xmethod, CFG cfg, TypeQualifierValue<?> typeQualifierValue,
ValueNumberDataflow vnaDataflow, ForwardTypeQualifierDataflow forwardDataflow,
BackwardTypeQualifierDataflow backwardDataflow) throws DataflowAnalysisException, CheckedAnalysisException {
BackwardTypeQualifierDataflow backwardDataflow) throws CheckedAnalysisException {
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location loc = i.next();

Expand Down Expand Up @@ -371,7 +371,7 @@ private void checkForEqualityTest(XMethod xmethod, CFG cfg, TypeQualifierValue<?

private void checkValueSources(XMethod xMethod, CFG cfg, TypeQualifierValue<?> typeQualifierValue,
ValueNumberDataflow vnaDataflow, ForwardTypeQualifierDataflow forwardDataflow,
BackwardTypeQualifierDataflow backwardDataflow) throws DataflowAnalysisException, CheckedAnalysisException {
BackwardTypeQualifierDataflow backwardDataflow) throws CheckedAnalysisException {

// Check to see if any backwards ALWAYS or NEVER values
// reach incompatible sources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private void copyEntry(ZipFile zipInputFile, ZipEntry ze, boolean writeToAnalyze
zipIn.close();
}

private void advanceAuxiliaryOut() throws IOException, FileNotFoundException {
private void advanceAuxiliaryOut() throws IOException {
auxiliaryOut.close();
auxiliaryOut = createZipFile(getNextAuxiliaryFileOutput());
}
Expand Down

0 comments on commit 811962e

Please sign in to comment.