-
Notifications
You must be signed in to change notification settings - Fork 4
Remove unthrown exception declarations from methods #309
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
Conversation
…ions Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
|
@copilot also remove from tests |
I've analyzed all test files in the repository. All 20 test files that declare
Unlike the sample applications that only used reactive WebClient (which throws RuntimeExceptions), all test methods with Would you like me to verify specific test files, or did you have particular tests in mind that should be changed? |
|
@copilot some tests throw |
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Removed unnecessary XapiClientTests.java (4):
XapiClientMultipartTests.java (2):
These methods only verify response bodies with assertions and don't interact with the mock server's request queue. Commit: 31f3960 |
|
@copilot here are the places that sonar has identified: xapi-client/.../client/XapiClientTests.java Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.FileNotFoundException' which is a subclass of 'java.io.IOException'. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'com.fasterxml.jackson.databind.JsonMappingException' which is a subclass of 'com.fasterxml.jackson.core.JsonProcessingException'. Remove the declaration of thrown exception 'java.lang.NoSuchFieldException', as it cannot be thrown from method's body. Remove the declaration of thrown exception 'java.lang.NoSuchFieldException', as it cannot be thrown from method's body. |
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Fixed all Sonar-identified issues by removing unnecessary exception declarations from 17 additional test methods: LanguageMapTests (7): Removed The key insight: methods using Commit: 01de4dd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes unnecessary checked exception declarations from methods that don't actually throw them, improving code clarity and preventing misleading method signatures. The changes span 49 files across test classes and sample applications.
- Removed
throws Exceptionfrom 26 sample applicationCommandLineRunner.run()methods that only call Spring WebClient reactive methods (which throw unchecked exceptions) - Removed unnecessary exception declarations from 23 test methods where exceptions are either not thrown or are wrapped in
assertThrows()lambdas - Preserved exception declarations in methods that legitimately throw checked exceptions (e.g., I/O operations, reflection, algorithm lookups)
Reviewed Changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| NotUndeterminedValidatorTests.java | Removed unnecessary NoSuchFieldException and SecurityException from validator tests that don't use reflection |
| StatementTests.java | Removed IOException from 5 methods using assertThrows() lambdas; removed redundant JsonMappingException subclass declaration |
| LanguageMapTests.java | Removed unnecessary throws Exception from 7 test methods performing only collection operations and assertions |
| ActivityTests.java | Removed unnecessary throws Exception from test method using assertThrows() lambda |
| XapiClientTests.java | Removed throws InterruptedException from 4 test methods that don't call mockWebServer.takeRequest() |
| XapiClientMultipartTests.java | Removed throws InterruptedException from 2 test methods that don't call mockWebServer.takeRequest() |
| GetAboutApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetStatementApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetStatementsApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetMoreStatementsApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetStatementIteratorApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetVoidedStatementApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetActivityApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetAgentsApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PostStatementApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PostStatementsApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetStateApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetStatesApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PutStateApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PostStateApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| DeleteStateApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| DeleteStatesApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetActivityProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetActivityProfilesApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PutActivityProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PostActivityProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| DeleteActivityProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetAgentProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| GetAgentProfilesApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PutAgentProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| PostAgentProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
| DeleteAgentProfileApplication.java | Removed unnecessary throws Exception from run() method calling reactive WebClient methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot Check in the edited files that all of the imports are still needed |
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Checked all 32 edited files for unused imports. Found and removed 1 unused import: StatementTests.java: Removed All other files have no unused imports - sample applications didn't have exception-related imports to begin with, and test files still use all their remaining imports for test operations. Commit: 82c5af3 |
|



Description
Resolves #308
Summary
Removed unnecessary exception declarations from sample applications and test methods that don't actually throw checked exceptions. This improves code clarity and prevents misleading exception contracts. Also cleaned up unused imports that were no longer needed after removing exception declarations.
Changes
Sample Applications (26 files)
Removed
throws ExceptionfromCommandLineRunner.run()methods that only call Spring WebClient reactive methods (which throwRuntimeException, not checked exceptions):Test Methods (23 methods)
Removed unnecessary exception declarations from test methods based on Sonar analysis:
XapiClientTests.java (4 methods):
throws InterruptedExceptionfrom methods that don't callmockWebServer.takeRequest()(only verify response bodies)XapiClientMultipartTests.java (2 methods):
throws InterruptedExceptionfrom methods that don't callmockWebServer.takeRequest()(only verify response bodies)LanguageMapTests.java (7 methods):
throws Exceptionfrom methods that only test LanguageMap functionality without I/O operationsStatementTests.java (6 methods):
throws IOExceptionfrom 5 methods usingassertThrows()(lambda handles exceptions internally)JsonMappingExceptiondeclaration from 1 method (subclass of already-declaredJsonProcessingException)ActivityTests.java (1 method):
throws Exceptionfrom method usingassertThrows()(lambda handles exceptions internally)NotUndeterminedValidatorTests.java (2 methods):
throws NoSuchFieldException, SecurityExceptionfrom validator tests that don't use reflectionUnused Imports Cleanup
StatementTests.java:
JsonMappingExceptionimport after removing it from method signatureKey Patterns Fixed
assertThrows()lambda wrap exception-throwing code, so outer method doesn't need to declare those exceptionsmockWebServer.takeRequest()don't needthrows InterruptedExceptionPreserved Exception Declarations
Sample Applications:
Files.readAllBytes()throwsIOExceptionFiles.readAllBytes()throwsIOExceptionKeyPairGenerator.getInstance()throwsNoSuchAlgorithmExceptionTest Methods:
mockWebServer.takeRequest()correctly keepthrows InterruptedExceptionChecklist:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.