Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public void visitNode(Tree tree) {
}

private static boolean instantiateOwnClass(Tree identifier, Symbol.TypeSymbol newClassTypeSymbol) {
Type enclosingClassType = JUtils.enclosingClass(identifier).type();
return enclosingClassType.equals(newClassTypeSymbol.type());
Symbol enclosingClass = JUtils.enclosingClass(identifier);
return enclosingClass != null && enclosingClass.type().equals(newClassTypeSymbol.type());
}

private static boolean hasOnlyStaticMethodsAndFields(Symbol.TypeSymbol newClassTypeSymbol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void visitBinaryExpression(BinaryExpressionTree tree) {

private static boolean withinStringConcatenation(BinaryExpressionTree tree) {
Tree parent = skipParenthesesUpwards(tree.parent());
return parent.is(Tree.Kind.PLUS) && ((BinaryExpressionTree) parent).symbolType().is("java.lang.String");
return parent != null && parent.is(Tree.Kind.PLUS) && ((BinaryExpressionTree) parent).symbolType().is("java.lang.String");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ private static Optional<MethodInvocationTree> getMethodInvocation(@Nullable Stat
}

private static boolean areAllSyntacticallyEquivalentExceptBoolean(MethodInvocationTree mit1, MethodInvocationTree mit2) {
if (skipParenthesesUpwards(mit1.parent()).kind() != skipParenthesesUpwards(mit2.parent()).kind()) {
Tree parent1 = skipParenthesesUpwards(mit1.parent());
Tree parent2 = skipParenthesesUpwards(mit2.parent());
if (parent1 == null || parent2 == null || parent1.kind() != parent2.kind()) {
// requires to have on both side a return statement, or on both side an expression statement.
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void endOfAnalysis(ModuleScannerContext context) {
// plus a percentage of total found — but the percentage component is capped at numberOfAdditionalIssuesThreshold.
numberOfIssuesToReport = numberOfFoundIssuesThreshold
+ Math.min((numberOfIssuesToReport * issuesToReportPercentage) / 100, numberOfAdditionalIssuesThreshold);
issuesFound.sort((a, b) -> b.brainScore - a.brainScore);
issuesFound.sort((a, b) -> Integer.compare(b.brainScore, a.brainScore));
}
var defaultContext = (DefaultModuleScannerContext) context;
for (int i = 0; i < numberOfIssuesToReport; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<Tree.Kind> nodesToVisit() {
public void visitNode(Tree tree) {
MethodTreeImpl methodTree = (MethodTreeImpl) tree;
Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass();
if (!enclosingClass.isInterface()) {
if (enclosingClass == null || !enclosingClass.isInterface()) {
return;
}
if (isPageableMethod(methodTree, enclosingClass.type()) && !hasPageableParameter(methodTree)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ private static boolean isRValue(IdentifierTree tree) {
if (parent instanceof AssignmentExpressionTree assignment) {
return assignment.variable() != tree;
}
if (parent == null) {
return true;
}
Tree grandParent = parent.parent();
// Note that an expression statement can't be a parenthesized expression, so we don't need to skip parentheses here
return !(parent.is(INCREMENT_KINDS) && parent.parent().is(Tree.Kind.EXPRESSION_STATEMENT));
return !(parent.is(INCREMENT_KINDS) && grandParent != null && grandParent.is(Tree.Kind.EXPRESSION_STATEMENT));
}

private static boolean isProperLocalVariable(VariableTree variable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public static VersionImpl parse(String versionString) {
@Override
public int compareTo(Version o) {
if (!Objects.equals(major, o.major())) {
return major - o.major();
return Integer.compare(major, o.major());
}
if (!Objects.equals(minor, o.minor())) {
return minor - o.minor();
return Integer.compare(minor, o.minor());
}
if (!Objects.equals(patch, o.patch())) {
if (patch == null || o.patch() == null) return 0;
return patch - o.patch();
return Integer.compare(patch, o.patch());
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ public int compare(JavaTextEdit a, JavaTextEdit b) {
AnalyzerMessage.TextSpan first = a.getTextSpan();
AnalyzerMessage.TextSpan second = b.getTextSpan();

int result = first.startLine - second.startLine;
int result = Integer.compare(first.startLine, second.startLine);
if (result != 0) {
return result;
}
result = first.startCharacter - second.startCharacter;
result = Integer.compare(first.startCharacter, second.startCharacter);
if (result != 0) {
return result;
}
result = first.endLine - second.endLine;
result = Integer.compare(first.endLine, second.endLine);
if (result != 0) {
return result;
}
return first.endCharacter - second.endCharacter;
return Integer.compare(first.endCharacter, second.endCharacter);
}
}
}
Expand Down
Loading