Skip to content

Commit

Permalink
Rename derived type to subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin-jaquier-sonarsource authored and Wohops committed May 14, 2020
1 parent 594d6f6 commit eae1272
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@
public class UnreachableCatchCheck {
void unreachable(boolean cond) {
try {
throwCustomDerivedException();
} catch (CustomDerivedException e) {
throwExtendsCustomException();
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Noncompliant
// ...
}

try {
throwUnknownException();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) {
// ...
}

try {
throwUnknownException();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (Unknown e) {
// ...
}

try {
unknown();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant
// ...
}

try {
throwCustomDerivedException();
throwExtendsCustomException();
unknown();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant, one unknown method
// ...
}

try {
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant
// ...
Expand All @@ -56,14 +56,14 @@ void throwUnknownException() throws Unknown {
throw new Unknown();
}

void throwCustomDerivedException() throws CustomDerivedException {
throw new CustomDerivedException();
void throwExtendsCustomException() throws ExtendsCustomException {
throw new ExtendsCustomException();
}

public static class CustomException extends Exception {
}

public static class CustomDerivedException extends CustomException {
public static class ExtendsCustomException extends CustomException {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
public class UnreachableCatchCheck {
void unreachable(boolean cond) {
try {
throwCustomDerivedException();
} catch (CustomDerivedException e) {
throwExtendsCustomException();
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Noncompliant [[sc=14;ec=29;secondary=14]] {{Remove this type because it is unreachable as hidden by previous catch blocks.}}
// ...
}

try {
throw new CustomDerivedException();
} catch (CustomDerivedException e) {
throw new ExtendsCustomException();
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException|IllegalStateException e) { // Noncompliant [[sc=14;ec=29]]
// ...
}

try {
new ThrowingCustomDerivedException();
} catch (CustomDerivedException e) {
new ThrowingExtendsCustomException();
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Noncompliant
// ...
Expand All @@ -42,29 +42,29 @@ void unreachable(boolean cond) {
}

try {
throwCustomDerivedDerivedException();
} catch (CustomDerivedDerivedException e) {
throwExtendsExtendsCustomException();
} catch (ExtendsExtendsCustomException e) {
// ...
} catch (CustomDerivedException e) { // Noncompliant [[secondary=46]]
} catch (ExtendsCustomException e) { // Noncompliant [[secondary=46]]
// ...
} catch (CustomException e) { // Noncompliant [[secondary=46,48]]
// ...
}

try {
throwCustomDerivedException();
} catch (CustomDerivedDerivedException e) {
throwExtendsCustomException();
} catch (ExtendsExtendsCustomException e) {
// ...
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Noncompliant [[secondary=58]]
// ...
}

try {
throwCustomDerivedException();
throwExtendsCustomException();
throwIOException();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (IOException e) { // Compliant
// ...
Expand All @@ -73,79 +73,79 @@ void unreachable(boolean cond) {
}

try {
throwCustomDerivedDerivedException();
throwExtendsExtendsCustomException();
throwIOException();
} catch (CustomDerivedException | IOException e) {
} catch (ExtendsCustomException | IOException e) {
// ...
} catch (CustomException e) { // FN, we don't support correctly the presence of another type of Exception
// ...
}

try {
throwCustomDerivedException();
throwExtendsCustomException();

class Inner {
void f() throws CustomException {
throwCustomException(); // not in the same scope
}
}
takeObject((Executable)(() -> throwCustomException())); // not in the same scope
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Noncompliant
// ...
}

try {
throwCustomException();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant, a CustomException is thrown, this is reachable
// ...
}

try {
throw new CustomException();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // compliant
// ...
}

try {
throwCustomException();
} catch (CustomDerivedDerivedException e) {
} catch (ExtendsExtendsCustomException e) {
// ...
} catch (CustomDerivedException e) { // Compliant, throwCustomException can throw one of his subtype
} catch (ExtendsCustomException e) { // Compliant, throwCustomException can throw one of his subtype
// ...
} catch (CustomException e) {
// ...
}

try {
throw new Exception();
} catch (CustomDerivedDerivedException e) {
} catch (ExtendsExtendsCustomException e) {
// ...
} catch (CustomDerivedException e) { // Compliant, FN in this case, but Exception could be one of his subtype
} catch (ExtendsCustomException e) { // Compliant, FN in this case, but Exception could be one of his subtype
// ...
} catch (Exception e) {
// ...
}

try {
throwCustomDerivedDerivedException();
throwExtendsExtendsCustomException();
throw new Exception();
} catch (CustomDerivedDerivedException e) {
} catch (ExtendsExtendsCustomException e) {
// ...
} catch (CustomDerivedException e) { // Compliant
} catch (ExtendsCustomException e) { // Compliant
// ...
} catch (Exception e) {
// ...
}

try {
throwCustomDerivedException();
} catch (CustomDerivedException e) {
throwExtendsCustomException();
} catch (ExtendsCustomException e) {
// ...
} catch (Throwable e) { // Compliant
// ...
Expand All @@ -155,21 +155,21 @@ void f() throws CustomException {
if (cond) {
throwCustomException();
} else {
throwCustomDerivedException();
throwExtendsCustomException();
}
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant, a CustomException is thrown, this is reachable
// ...
}

try {
if (cond) {
throwCustomDerivedException();
throwExtendsCustomException();
} else {
throwCustomException();
}
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant
// ...
Expand All @@ -182,10 +182,10 @@ void f() throws CustomException {
}

try(InputStream input = new FileInputStream("reportFileName")) {
throwCustomDerivedException();
throwExtendsCustomException();
} catch (FileNotFoundException e) {
} catch (IOException e) { // Compliant, close throws an IOException
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // FN
// ...
Expand Down Expand Up @@ -216,17 +216,17 @@ public void close() throws FileNotFoundException {
}

try {
throwCustomDerivedException();
throwOtherCustomDerivedException();
} catch (CustomDerivedException e) {
throwExtendsCustomException();
throwOtherOtherExtendsCustomException();
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant
// ...
}

try {
throwBoth();
} catch (CustomDerivedException e) {
} catch (ExtendsCustomException e) {
// ...
} catch (CustomException e) { // Compliant
// ...
Expand All @@ -238,19 +238,19 @@ void throwCustomException() throws CustomException {
throw new CustomException();
}

void throwCustomDerivedException() throws CustomDerivedException {
throw new CustomDerivedException();
void throwExtendsCustomException() throws ExtendsCustomException {
throw new ExtendsCustomException();
}

void throwBoth() throws CustomDerivedException,OtherCustomDerivedException {
void throwBoth() throws ExtendsCustomException, OtherExtendsCustomException {
}

void throwOtherCustomDerivedException() throws OtherCustomDerivedException {
throw new OtherCustomDerivedException();
void throwOtherOtherExtendsCustomException() throws OtherExtendsCustomException {
throw new OtherExtendsCustomException();
}

void throwCustomDerivedDerivedException() throws CustomDerivedDerivedException {
throw new CustomDerivedDerivedException();
void throwExtendsExtendsCustomException() throws ExtendsExtendsCustomException {
throw new ExtendsExtendsCustomException();
}

void throwIOException() throws IOException {
Expand All @@ -268,17 +268,17 @@ void takeObject(Object o) {
public static class CustomException extends Exception {
}

public static class CustomDerivedException extends CustomException {
public static class ExtendsCustomException extends CustomException {
}

public static class OtherCustomDerivedException extends CustomException {
public static class OtherExtendsCustomException extends CustomException {
}

public static class CustomDerivedDerivedException extends CustomDerivedException {
public static class ExtendsExtendsCustomException extends ExtendsCustomException {
}

class ThrowingCustomDerivedException {
ThrowingCustomDerivedException() throws CustomDerivedException {
class ThrowingExtendsCustomException {
ThrowingExtendsCustomException() throws ExtendsCustomException {

}
}
Expand Down
Loading

0 comments on commit eae1272

Please sign in to comment.