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

Fail to detect exception class in try catch block #41

Closed
csoroiu opened this issue Aug 8, 2017 · 1 comment
Closed

Fail to detect exception class in try catch block #41

csoroiu opened this issue Aug 8, 2017 · 1 comment

Comments

@csoroiu
Copy link
Contributor

csoroiu commented Aug 8, 2017

I spotted 2 issues with try...catch blocks.
As a context i am using master version and the java15/java16 as signatures.

  1. First is related to the fact that animal-sniffer is not reporting an exception class not available in java < 1.7. There should be an error reported on line 5, as java.lang.ReflectiveOperationException is not present in java 5 & 6 for the code below.
public void exceptionClassNotAvailableInJava6() {
    try {
        Method method = TestClass.class.getDeclaredMethod("emptyMethod");
        method.invoke(null);
    } catch (ReflectiveOperationException exception) {
        logException(exception);
    }
}
  1. The second is a little bit trickier. The effect of the below multi-catch statement is that the runtime type of the exception variable, when compiled with java7 or 8, is java.lang.ReflectiveOperationException and the frame that is generated contains java.lang.ReflectiveOperationException on the stack. Same as above, there should be an error reported on line 5, as java.lang.ReflectiveOperationException is not present in java 5 & 6 for the code below. That particular exception was added in the middle of the hierarchy in Java 7.
public void exceptionMultiCatch() {
    try {
        Method method = TestClass.class.getDeclaredMethod("emptyMethod");
        method.invoke(null);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exception) {
        logException(exception);
    }
}

Both code block from above pass the check even if they should not.
I'll post a PR soon on this matter.

@csoroiu csoroiu changed the title Fail to detect exception class in empty try catch block Fail to detect exception class in try catch block Aug 8, 2017
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Aug 8, 2017
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Aug 8, 2017
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Jul 25, 2018
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Jul 25, 2018
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Jul 25, 2018
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Jul 25, 2018
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Aug 1, 2018
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Aug 1, 2018
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Feb 2, 2019
csoroiu added a commit to csoroiu/animal-sniffer that referenced this issue Feb 2, 2019
olamy pushed a commit that referenced this issue Mar 3, 2019
@csoroiu
Copy link
Contributor Author

csoroiu commented Apr 23, 2020

fixed by #47

@csoroiu csoroiu closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant