Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about unused declared thrown exceptions in Eclipse #273

Closed
wilkinsona opened this issue May 13, 2021 · 2 comments
Closed

Warn about unused declared thrown exceptions in Eclipse #273

wilkinsona opened this issue May 13, 2021 · 2 comments
Assignees
Milestone

Comments

@wilkinsona
Copy link
Contributor

wilkinsona commented May 13, 2021

We have numerous places in Boot where we've declared that an exception is thrown when it isn't or when the exception is a RuntimeException so it doesn't need to be declared. There's a PR that removes them which I am in favour of. I think it would also be nice to try and stop them reappearing. To that end, we could change the Eclipse JDT core preferences. Instead of the following:

org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled

We'd use the following:

org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=disabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=disabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled

The changes above will result in warnings being generated for checked exceptions that are unnecessarily declared as thrown. It won't help with unchecked exceptions.

@wilkinsona
Copy link
Contributor Author

wilkinsona commented May 13, 2021

Thinking some more, we may want to leave the following two settings unchanged:

org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled

This will allow an exception to be declared thrown if it's mentioned in the javadoc or if it comes from the signature of a method that's being overridden.

@weixsun
Copy link

weixsun commented May 13, 2021

This will allow an exception to be declared thrown if it's mentioned in the javadoc or if it comes from the signature of a method that's being overridden.

@wilkinsona yes, when I was erasing an exception that was never thrown, I deliberately kept the case you mentioned.

e.g.:

class TestFilter implements Filter {
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// do something
	}
}

IOException and ServletException should not be erased even if never thrown.

@philwebb philwebb added this to the 0.0.x milestone May 13, 2021
@wilkinsona wilkinsona self-assigned this May 24, 2022
@wilkinsona wilkinsona modified the milestones: 0.0.x, 0.0.32 May 24, 2022
@wilkinsona wilkinsona changed the title Warn about unused declared thrown exceptions Warn about unused declared thrown exceptions in Eclipse May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants