[java] Update rule PreserveStackTrace#3179
Merged
Merged
Conversation
bf84c06 to
f186b13
Compare
Generated by 🚫 Danger |
adangel
reviewed
Apr 10, 2021
adangel
left a comment
Member
There was a problem hiding this comment.
I think, there are a few cases of FN/FP we should verify:
Previously reported on master, now with pmd7 they would be ok (FN) -> Is this really correct?
- https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-context/src/main/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptor.java#L110
- same case: https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-context/src/main/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptor.java#L114
- There is some method called, but the original exception
InvocationTargetException exis not handed in as a argument. Soexis lost. - In that case, this is a InvocationTargetException, which wraps the more interesting exception, so this could be considered ok... but I didn't see, that we now specifically check for "getTargetException" ...
- I think, we should keep reporting this situation unless we decided to change the rule to say "for InvocationTargetException, it is ok to ignore this exception as long as the target exception is used"
- A similar case would then be the MBean wrapping exception, e.g. https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java#L443
- https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java#L390
- same case: https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java#L621
- The original "PersistenceExeption ex" is ignored if there is a "getCause"
- Like the above, this might be ok, but in that case, this would be a hibernate specific exception
- https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-web/src/main/java/org/springframework/remoting/caucho/HessianClientInterceptor.java#L260
- Only the targetException is used and the original "InvocationTargetException ex" is ignored
- https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-web/src/test/java/org/springframework/protobuf/Msg.java#L95
- we can't be sure, that
e.setUnfinishedMessage(this)returns the same exception "e" or returns a new exception without the original stacktrace
- we can't be sure, that
- https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-web/src/test/java/org/springframework/protobuf/Msg.java#L97
- Here definitely a new exception is created without preserving the stacktrace of "e"
New violations, that are probably false positives:
- https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java#L265
- The original exception "ex" is passed into a constructor ("Problem") and the resulting object (instance of "Problem") is passed into a new custom exception
- So we could assume, that "ex" is used (although we don't know for sure)
- On master, we didn't report this. We probably assumed, that the stacktrace is preserved, if the original exception is passed into the new exception in any way - even if it is passed in indirectly like here. And we didn't care, whether the correct constructor of Exception is used.
These are cases where the exception is consumed by the constructor transitively. Since we're processing everything recursively now we're effectively exploring the dataflow graph... only in an indirect way, without respect for ordering of statements... This can be improved later, and ideally generalized to help other rules.
This will avoid some FPs at the cost of some FNs. The rule doesn't handle branches in control flow or loops.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by travis)