private void reportAll(CheckerContext context) { CheckerDispatcher checkerDispatcher = (CheckerDispatcher) context; methodInvocations.pop().stream() .filter(mit -> mit.symbol().isMethodSymbol()) .forEach(mit -> reportYields(mit, checkerDispatcher)); }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { addThrownTypes(tree.symbol()); super.visitMethodInvocation(tree); }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (isThrowingJavaLangException(tree.symbol())) { return; } super.visitMethodInvocation(tree); }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { super.visitMethodInvocation(tree); visitMethodSymbol(tree.symbol()); }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { if(mit.symbol().name().equals("setAccessible")) { checkAccessibilityUpdate(mit); } else { reportIssue(mit, "Make sure that this accessibility bypass is safe here."); } }
private boolean checkEmptyParams(MethodInvocationTree mit, Collection<?> params) { if (params.isEmpty() && (!LEVELS.contains(mit.symbol().name()) || mit.arguments().size() > 1)) { reportIssue(mit, "String contains no format specifiers."); return true; } return false; }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (this.owner == tree.symbol().owner()) { return; } tree.arguments().stream().filter(ExpressionUtils::isThis).forEach(this::report); super.visitMethodInvocation(tree); }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { Symbol symbol = tree.symbol(); if(symbol.isUnknown()) { unknownInvocations.put(ExpressionUtils.methodName(tree).name(), tree); } else if (isPrivateMethodOfOuterClass(symbol)) { usages.add(symbol); } super.visitMethodInvocation(tree); }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { if (mit.symbol().name().equals("setProperty")) { String stringConstant = ConstantUtils.resolveAsStringConstant(mit.arguments().get(0)); if ("logback.configurationFile".equals(stringConstant)) { reportIssue(mit, MESSAGE); } } else { reportIssue(mit, MESSAGE); } }
private void checkMethodInvocation(MethodInvocationTree node) { Symbol symbol = node.symbol(); if (symbol.isMethodSymbol()) { List<Type> types = ((Symbol.MethodSymbol) symbol).thrownTypes(); if (!types.isEmpty()) { addIssueIfNotCatched(types, ExpressionUtils.methodName(node), "Add a \"try/catch\" block for \"" + symbol.name() + "\"."); } } }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { if (!"openConnection".equals(mit.symbol().name()) || isCastToHttpUrlConnection(mit.parent())) { reportIssue(ExpressionUtils.methodName(mit), "Make sure that this http request is sent safely."); } }
private static ExpressionTree getActualArgument(MethodInvocationTree mit) { int arity = mit.arguments().size(); ExpressionTree arg = mit.arguments().get(arity - 1); // Check for assert equals method with delta if (arity > 2 && (arity == 4 || ((Symbol.MethodSymbol) mit.symbol()).parameterTypes().stream().allMatch(AssertionArgumentOrderCheck::isDoubleOrFloat))) { // last arg is actually delta, take the previous last to get the actual arg. arg = mit.arguments().get(arity - 2); } return arg; }
private static boolean isGetPropertyWithDefaultValue(MethodInvocationTree mit) { Symbol symbol = mit.symbol(); if (symbol.isMethodSymbol() && symbol.owner().type().is("java.util.Properties")) { return "getProperty".equals(symbol.name()) && mit.arguments().size() == 2; } return false; } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (tree.symbol().isUnknown()) { context.reportIssue(this, methodName(tree.methodSelect()), "Method not resolved"); } super.visitMethodInvocation(tree); }
private static boolean throwsNoSuchElementException(MethodInvocationTree methodInvocationTree) { Symbol symbol = methodInvocationTree.symbol(); if (!symbol.isMethodSymbol()) { return false; } if (throwsNoSuchElementException(((Symbol.MethodSymbol) symbol).thrownTypes())) { return true; } MethodJavaType methodJavaType = (MethodJavaType) ExpressionUtils.methodName(methodInvocationTree).symbolType(); return throwsNoSuchElementException(methodJavaType.thrownTypes()); }
private void buildMethodInvocation(MethodInvocationTree mit) { handleExceptionalPaths(mit.symbol()); currentBlock.elements.add(mit); build(mit.arguments()); if (mit.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) mit.methodSelect(); build(memberSelect.expression()); } else { build(mit.methodSelect()); } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { Symbol symbol = tree.symbol(); if (tree.methodSelect().is(Tree.Kind.IDENTIFIER) && isCallToSuperclassMethod(symbol)) { String methodName = ((IdentifierTree) tree.methodSelect()).name(); reportIssue(ExpressionUtils.methodName(tree), "Prefix this call to \"" + methodName + "\" with \"super.\"."); } super.visitMethodInvocation(tree); }