diff --git a/java-frontend/src/main/java/org/sonar/java/se/checks/ExceptionalYieldChecker.java b/java-frontend/src/main/java/org/sonar/java/se/checks/ExceptionalYieldChecker.java index 054a4551a6c..c27cc11b84f 100644 --- a/java-frontend/src/main/java/org/sonar/java/se/checks/ExceptionalYieldChecker.java +++ b/java-frontend/src/main/java/org/sonar/java/se/checks/ExceptionalYieldChecker.java @@ -76,9 +76,9 @@ private void reportIssue(ExplodedGraph.Node node, ExceptionalCheckBasedYield yie for (List argumentFlow : argumentsFlows) { for (List exceptionFlow : exceptionFlows) { flows.add(ImmutableList.builder() - .addAll(Lists.reverse(argumentFlow)) + .addAll(exceptionFlow) .add(methodInvocationMessage) - .addAll(Lists.reverse(exceptionFlow)) + .addAll(argumentFlow) .build()); } } diff --git a/java-frontend/src/test/files/se/MethodInvocationLeadingToArithmeticException.java b/java-frontend/src/test/files/se/MethodInvocationLeadingToArithmeticException.java index dcb4cdb2027..ff4d383688d 100644 --- a/java-frontend/src/test/files/se/MethodInvocationLeadingToArithmeticException.java +++ b/java-frontend/src/test/files/se/MethodInvocationLeadingToArithmeticException.java @@ -9,16 +9,16 @@ void foo1() { } void foo2() { - A.divByZeroIfArg1Zero( // Noncompliant [[flows=foo2]] {{A division by zero will occur when invoking method divByZeroIfArg1Zero().}} flow@foo2 [[order=5]] {{'divByZeroIfArg1Zero()' is invoked.}} - 42, // flow@foo2 [[order=1]] {{non-null}} flow@foo2 [[order=2]] {{non-zero}} - 0); // flow@foo2 [[order=3]] {{non-null}} flow@foo2 [[order=4]] {{zero}} + A.divByZeroIfArg1Zero( // Noncompliant [[flows=foo2]] {{A division by zero will occur when invoking method divByZeroIfArg1Zero().}} flow@foo2 [[order=4]] {{'divByZeroIfArg1Zero()' is invoked.}} + 42, // flow@foo2 [[order=8]] {{non-null}} flow@foo2 [[order=7]] {{non-zero}} + 0); // flow@foo2 [[order=6]] {{non-null}} flow@foo2 [[order=5]] {{zero}} } void foo3(int j) { - int i = 42; // flow@foo3 [[order=1]] {{non-null}} flow@foo3 [[order=2]] {{non-zero}} + int i = 42; // flow@foo3 [[order=8]] {{non-null}} flow@foo3 [[order=7]] {{non-zero}} divByZeroIfArg1Zero(i, j); // Compliant - if (j == 0) { // flow@foo3 [[order=3]] {{Implies 'j' is non-null.}} flow@foo3 [[order=4]] {{Implies 'j' is zero.}} - divByZeroIfArg1Zero(i, j); // Noncompliant [[flows=foo3]] {{A division by zero will occur when invoking method divByZeroIfArg1Zero().}} flow@foo3 [[order=5]] {{'divByZeroIfArg1Zero()' is invoked.}} + if (j == 0) { // flow@foo3 [[order=6]] {{Implies 'j' is non-null.}} flow@foo3 [[order=5]] {{Implies 'j' is zero.}} + divByZeroIfArg1Zero(i, j); // Noncompliant [[flows=foo3]] {{A division by zero will occur when invoking method divByZeroIfArg1Zero().}} flow@foo3 [[order=4]] {{'divByZeroIfArg1Zero()' is invoked.}} } } @@ -68,7 +68,7 @@ static int divByZeroIfZero(int i) { } static int divByZeroIfArg1Zero(int x, int y) { - return x / y; // flow@foo2 [[order=6]] {{Implies 'y' is zero.}} flow@foo2 [[order=7]] {{Implies 'y' is non-null.}} flow@foo2 [[order=8]] {{'ArithmeticException' is thrown here.}} flow@foo3 [[order=6]] {{Implies 'y' is zero.}} flow@foo3 [[order=7]] {{Implies 'y' is non-null.}} flow@foo3 [[order=8]] {{'ArithmeticException' is thrown here.}} + return x / y; // flow@foo2 [[order=3]] {{Implies 'y' is zero.}} flow@foo2 [[order=2]] {{Implies 'y' is non-null.}} flow@foo2 [[order=1]] {{'ArithmeticException' is thrown here.}} flow@foo3 [[order=3]] {{Implies 'y' is zero.}} flow@foo3 [[order=2]] {{Implies 'y' is non-null.}} flow@foo3 [[order=1]] {{'ArithmeticException' is thrown here.}} } static int throwsExceptionIfArg1Zero(int i, int j) { diff --git a/java-frontend/src/test/files/se/MethodInvocationLeadingToNPE.java b/java-frontend/src/test/files/se/MethodInvocationLeadingToNPE.java index 4c6db53c3ea..f5bdf5c90bb 100644 --- a/java-frontend/src/test/files/se/MethodInvocationLeadingToNPE.java +++ b/java-frontend/src/test/files/se/MethodInvocationLeadingToNPE.java @@ -11,8 +11,8 @@ void foo1(Object o) { } void foo2(Object o) { - if (o == null) { // flow@foo2 [[order=1]] {{Implies 'o' is null.}} - A.npeIfNull(o); // Noncompliant [[flows=foo2]] [[sc=9;ec=18]] {{NullPointerException will be thrown when invoking method npeIfNull().}} flow@foo2 [[order=2]] {{'npeIfNull()' is invoked.}} + if (o == null) { // flow@foo2 [[order=4]] {{Implies 'o' is null.}} + A.npeIfNull(o); // Noncompliant [[flows=foo2]] [[sc=9;ec=18]] {{NullPointerException will be thrown when invoking method npeIfNull().}} flow@foo2 [[order=3]] {{'npeIfNull()' is invoked.}} } o.toString(); // Compliant - can not be reached with 'o 'being NULL, as the NPE is triggered insde bar() @@ -34,36 +34,36 @@ void foo4(Object o) { } void foo5(Object o) { - if (o == null) { // flow@foo5 [[order=1]] {{Implies 'o' is null.}} + if (o == null) { // flow@foo5 [[order=3]] {{Implies 'o' is null.}} nullable(o); // Noncompliant [[flows=foo5]] [[sc=7;ec=15]] {{NullPointerException will be thrown when invoking method nullable().}} flow@foo5 [[order=2]] {{'nullable()' is invoked.}} } o.toString(); // Compliant - can not be reached with 'o 'being NULL, as the NPE is triggered insde bar() } void foo6(Object o, boolean b1, boolean b2) { - if (!b1 && b2) { // flow@foo6 [[order=1]] {{Implies 'b1' is true.}} + if (!b1 && b2) { // flow@foo6 [[order=5]] {{Implies 'b1' is true.}} npeIfArg0IsTrueAndArg1IsNull(b1, o, b2); // Compliant } - if (o == null && b1) { // flow@foo6 [[order=2]] {{Implies 'o' is null.}} + if (o == null && b1) { // flow@foo6 [[order=4]] {{Implies 'o' is null.}} npeIfArg0IsTrueAndArg1IsNull(b1, o, b2); // Noncompliant [[flows=foo6]] [[sc=7;ec=35]] {{NullPointerException will be thrown when invoking method npeIfArg0IsTrueAndArg1IsNull().}} flow@foo6 [[order=3]] {{'npeIfArg0IsTrueAndArg1IsNull()' is invoked.}} } } static void npeIfNull(Object o) { - o.toString(); // flow@foo2 [[order=3]] {{...}} flow@foo2 [[order=4]] {{'NullPointerException' is thrown here.}} + o.toString(); // flow@foo2 [[order=2]] {{...}} flow@foo2 [[order=1]] {{'NullPointerException' is thrown here.}} } static void npeIfArg0IsTrueAndArg1IsNull(boolean arg0, Object arg1, boolean arg2) { - if (arg1 != null) { // flow@foo6 [[order=4]] {{Implies 'arg1' is null.}} + if (arg1 != null) { // flow@foo6 [[order=2]] {{Implies 'arg1' is null.}} return; } if (arg0) { // only b2 has consequences on NPE - arg1.toString(); // Noncompliant {{NullPointerException might be thrown as 'arg1' is nullable here}} flow@foo6 [[order=5]] {{'NullPointerException' is thrown here.}} + arg1.toString(); // Noncompliant {{NullPointerException might be thrown as 'arg1' is nullable here}} flow@foo6 [[order=1]] {{'NullPointerException' is thrown here.}} } } static void nullable(@Nullable Object o) { - o.toString(); // Noncompliant {{NullPointerException might be thrown as 'o' is nullable here}} flow@foo5 [[order=3]] {{'NullPointerException' is thrown here.}} + o.toString(); // Noncompliant {{NullPointerException might be thrown as 'o' is nullable here}} flow@foo5 [[order=1]] {{'NullPointerException' is thrown here.}} } } diff --git a/java-frontend/src/test/files/se/MethodInvocationLeadingToNSEE.java b/java-frontend/src/test/files/se/MethodInvocationLeadingToNSEE.java index f86be1c7e4e..ddf76b01c59 100644 --- a/java-frontend/src/test/files/se/MethodInvocationLeadingToNSEE.java +++ b/java-frontend/src/test/files/se/MethodInvocationLeadingToNSEE.java @@ -37,9 +37,9 @@ void foo5() { } void foo6(boolean b) { - Optional o = getOptional(); // flow@foo6 [[order=1]] {{'getOptional()' returns non-null.}} flow@foo6 [[order=2]] {{'o' is assigned non-null.}} - if (b) { // flow@foo6 [[order=3]] {{Implies 'b' is true.}} - A.nseeIfCalledAndTrue(b, o); // Noncompliant [[flows=foo6]] {{NoSuchElementException will be thrown when invoking method nseeIfCalledAndTrue() without verifying Optional parameter.}} flow@foo6 [[order=4]] {{'nseeIfCalledAndTrue()' is invoked.}} + Optional o = getOptional(); // flow@foo6 [[order=6]] {{'getOptional()' returns non-null.}} flow@foo6 [[order=5]] {{'o' is assigned non-null.}} + if (b) { // flow@foo6 [[order=4]] {{Implies 'b' is true.}} + A.nseeIfCalledAndTrue(b, o); // Noncompliant [[flows=foo6]] {{NoSuchElementException will be thrown when invoking method nseeIfCalledAndTrue() without verifying Optional parameter.}} flow@foo6 [[order=3]] {{'nseeIfCalledAndTrue()' is invoked.}} } else { nseeIfCalledAndTrue(b, o); // Compliant } @@ -62,7 +62,7 @@ static void nseeIfCalled(Optional o) { static void nseeIfCalledAndTrue(boolean b, Optional o) { if (b) { - o.get(); // Noncompliant {{Call "o.isPresent()" before accessing the value.}} flow@foo6 [[order=5]] {{...}} flow@foo6 [[order=6]] {{'NoSuchElementException' is thrown here.}} + o.get(); // Noncompliant {{Call "o.isPresent()" before accessing the value.}} flow@foo6 [[order=2]] {{...}} flow@foo6 [[order=1]] {{'NoSuchElementException' is thrown here.}} } else if (o.isPresent()) { o.get(); }