Details about the known misuse from the MUBench dataset.
Description: | Examiner.java calls 'scanner.next()' on 'java.util.Scanner scanner' without checking
if there are more elements. Because the scanner is built from the JavaSource parameter
that can be invalid (e.g., an empty source), this can lead to a runtime exception
without a useful error message.
This pull request adds an error message and a test. |
Fix Description: |
(see diff) |
Violation Types: |
- missing/condition/value_or_state
|
In File: | de/strullerbaumann/visualee/examiner/Examiner.java |
In Method: | jumpOverJavaToken(String, Scanner) |
Code with Misuse: |
class Examiner {
protected static String jumpOverJavaToken(String token, Scanner scanner) {
String nextToken = token;
while (isAJavaToken(nextToken)) {
if (nextToken.startsWith("@") && nextToken.indexOf('(') > -1 && !nextToken.endsWith(")")) {
nextToken = scanAfterClosedParenthesis(nextToken, scanner);
} else {
nextToken = scanner.next();
}
}
return nextToken;
}
}
|
Code with Pattern(s): |
abstract class JumpOverJavaToken extends Examiner {
protected static String jumpOverJavaToken(String token, Scanner scanner) {
String nextToken = token;
while (isAJavaToken(nextToken)) {
if (!scanner.hasNext()) {
throw new IllegalArgumentException("Insufficient number of tokens to jump over");
}
if (nextToken.startsWith("@") && nextToken.indexOf('(') > -1 && !nextToken.endsWith(")")) {
nextToken = scanAfterClosedParenthesis(nextToken, scanner);
} else {
nextToken = scanner.next();
}
}
return nextToken;
}
}
|