private boolean isSession(MethodInvocationTree methodInvocation) { return methodInvocation.symbolType().fullyQualifiedName().equals(JCR_SESSION); }
private boolean isResourceResolver(MethodInvocationTree invocationTree) { return invocationTree.symbolType().fullyQualifiedName().equals(RESOURCE_RESOLVER_NAME); }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (IS_ZIP_ENTRY.test(tree.symbolType())) { context.reportIssue(this, tree, ISSUE_MESSAGE); } super.visitMethodInvocation(tree); } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (IS_ZIP_ENTRY.test(tree.symbolType())) { context.reportIssue(this, tree, ISSUE_MESSAGE); } super.visitMethodInvocation(tree); } }
private boolean methodOpeningResource(MethodInvocationTree mit) { return !isWithinTryHeader(mit) && !excludedByRuleOption(mit.symbolType()) && !handledByFramework(mit) && (JDBC_RESOURCE_CREATIONS.anyMatch(mit) || STREAMS_BACKED_BY_RESOURCE.anyMatch(mit) || (needsClosing(mit.symbolType()) && !CLOSEABLE_EXCEPTIONS.anyMatch(mit) && mitHeuristics(mit))); }
private boolean methodOpeningResource(MethodInvocationTree mit) { return !isWithinTryHeader(mit) && !excludedByRuleOption(mit.symbolType()) && !handledByFramework(mit) && (JDBC_RESOURCE_CREATIONS.anyMatch(mit) || STREAMS_BACKED_BY_RESOURCE.anyMatch(mit) || (needsClosing(mit.symbolType()) && !CLOSEABLE_EXCEPTIONS.anyMatch(mit) && mitHeuristics(mit))); }
private static boolean isAcceptedTypeOrUnmodifiableMethodCall(MethodInvocationTree mit) { Type type = mit.symbolType(); return type.isUnknown() || isAcceptedType(type, ACCEPTED_TYPES) || UNMODIFIABLE_METHOD_CALLS.anyMatch(mit); }
private static boolean isAcceptedTypeOrUnmodifiableMethodCall(MethodInvocationTree mit) { Type type = mit.symbolType(); return type.isUnknown() || isAcceptedType(type, ACCEPTED_TYPES) || UNMODIFIABLE_METHOD_CALLS.anyMatch(mit); }
private static String name(Tree tree) { if (tree.is(Tree.Kind.NEW_CLASS)) { return ((NewClassTree) tree).symbolType().name(); } MethodInvocationTree mit = (MethodInvocationTree) tree; if (mit.symbolType().isVoid()) { return mit.symbol().owner().name(); } return mit.symbolType().name(); }
private static String name(Tree tree) { if (tree.is(Tree.Kind.NEW_CLASS)) { return ((NewClassTree) tree).symbolType().name(); } return ((MethodInvocationTree) tree).symbolType().name(); }
private static String name(Tree tree) { if (tree.is(Tree.Kind.NEW_CLASS)) { return ((NewClassTree) tree).symbolType().name(); } return ((MethodInvocationTree) tree).symbolType().name(); }
private static String name(Tree tree) { if (tree.is(Tree.Kind.NEW_CLASS)) { return ((NewClassTree) tree).symbolType().name(); } MethodInvocationTree mit = (MethodInvocationTree) tree; if (mit.symbolType().isVoid()) { return mit.symbol().owner().name(); } return mit.symbolType().name(); }
private void checkForUnboxing(ExpressionTree expressionTree) { if (!expressionTree.is(Tree.Kind.METHOD_INVOCATION)) { return; } MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree; if (isUnboxingMethodInvocation(methodInvocationTree)) { ExpressionTree methodSelect = methodInvocationTree.methodSelect(); if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) methodSelect; ExpressionTree unboxedExpression = memberSelectExpressionTree.expression(); String unboxingResultTypeName = methodInvocationTree.symbolType().fullyQualifiedName(); if (unboxingResultTypeName.equals(PRIMITIVE_TYPES_BY_WRAPPER.get(unboxedExpression.symbolType().fullyQualifiedName()))) { addUnboxingIssue(expressionTree, unboxedExpression); } } } }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { Tree parent = mit.parent(); if (parent.is(Tree.Kind.EXPRESSION_STATEMENT) || (parent.is(Tree.Kind.VARIABLE) && ((VariableTree) parent).symbol().usages().isEmpty())) { reportIssue(parent, "Do something with the \"" + mit.symbolType().name() + "\" value returned by \"" + mit.symbol().name() + "\"."); } }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { Tree parent = mit.parent(); if (parent.is(Tree.Kind.EXPRESSION_STATEMENT) || (parent.is(Tree.Kind.VARIABLE) && ((VariableTree) parent).symbol().usages().isEmpty())) { reportIssue(parent, "Do something with the \"" + mit.symbolType().name() + "\" value returned by \"" + mit.symbol().name() + "\"."); } }
@Override public void visitNode(Tree tree) { if (!excluded.contains(tree)) { super.visitNode(tree); if (tree.is(Tree.Kind.VARIABLE)) { VariableTree variableTree = (VariableTree) tree; boolean foundIssue = checkForbiddenTypes(variableTree.simpleName(), variableTree.type().symbolType()); if (foundIssue) { excluded.add(variableTree.initializer()); } } else if (tree.is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree mit = (MethodInvocationTree) tree; checkForbiddenTypes(ExpressionUtils.methodName(mit), mit.symbolType()); } } }
@Override public void visitNode(Tree tree) { ExpressionStatementTree est = (ExpressionStatementTree) tree; if (est.expression().is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree mit = (MethodInvocationTree) est.expression(); Type methodType = mit.symbolType(); if (!returnsVoid(methodType) && isCheckedType(mit)) { addIssue(tree, "The return value of \"" + methodName(mit) + "\" must be used."); } } }
@Override public void visitMethodInvocation(MethodInvocationTree syntaxNode) { if (syntaxNode.methodSelect().is(Tree.Kind.MEMBER_SELECT) && needsClosing(syntaxNode.symbolType())) { final ExpressionTree targetExpression = ((MemberSelectExpressionTree) syntaxNode.methodSelect()).expression(); if (targetExpression.is(Tree.Kind.IDENTIFIER) && !isWithinTryHeader(syntaxNode) && (syntaxNode.symbol().isStatic() || isJdbcResourceCreation(targetExpression))) { programState = programState.addConstraint(programState.peekValue(), new ObjectConstraint(false, false, syntaxNode, Status.OPENED)); } } }
@Override public void checkEndOfExecutionPath(CheckerContext context, ConstraintManager constraintManager) { final List<ObjectConstraint> constraints = context.getState().getFieldConstraints(Status.OPENED); for (ObjectConstraint constraint : constraints) { Tree syntaxNode = constraint.syntaxNode(); String name = null; if (syntaxNode.is(Tree.Kind.NEW_CLASS)) { name = ((NewClassTree) syntaxNode).identifier().symbolType().name(); } else if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) { name = ((MethodInvocationTree) syntaxNode).symbolType().name(); } if(name != null) { context.reportIssue(syntaxNode, this, "Close this \"" + name + "\"."); } } }
private void visitMethodInvocationTree(MethodInvocationTree mit) { ExpressionTree methodSelect = mit.methodSelect(); if (isValueOfInvocation(mit)) { ExpressionTree arg0 = mit.arguments().get(0); checkForUnboxing(arg0); checkForUselessUnboxing(mit.symbolType(), methodSelect, arg0); } else if (isUnboxingMethodInvocation(mit)) { if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) { checkForBoxing(((MemberSelectExpressionTree) methodSelect).expression()); } } else { Symbol symbol = mit.symbol(); if (symbol.isMethodSymbol()) { checkMethodInvocationArguments(mit, ((Symbol.MethodSymbol) symbol).parameterTypes()); } } }