예제 #1
0
 /** Case 1: Check for null dereferencing */
 @Override
 public Void visitMemberSelect(MemberSelectTree node, Void p) {
   boolean isType = node.getExpression().getKind() == Kind.PARAMETERIZED_TYPE;
   if (!TreeUtils.isSelfAccess(node) && !isType) {
     checkForNullability(node.getExpression(), DEREFERENCE_OF_NULLABLE);
   }
   return super.visitMemberSelect(node, p);
 }
예제 #2
0
 @Override
 protected void checkMethodInvocability(
     AnnotatedExecutableType method, MethodInvocationTree node) {
   if (!TreeUtils.isSelfAccess(node)
       &&
       // Static methods don't have a receiver
       method.getReceiverType() != null) {
     // TODO: should all or some constructors be excluded?
     // method.getElement().getKind() != ElementKind.CONSTRUCTOR) {
     Set<AnnotationMirror> recvAnnos = atypeFactory.getReceiverType(node).getAnnotations();
     AnnotatedTypeMirror methodReceiver = method.getReceiverType().getErased();
     AnnotatedTypeMirror treeReceiver = methodReceiver.shallowCopy(false);
     AnnotatedTypeMirror rcv = atypeFactory.getReceiverType(node);
     treeReceiver.addAnnotations(rcv.getEffectiveAnnotations());
     // If receiver is Nullable, then we don't want to issue a warning
     // about method invocability (we'd rather have only the
     // "dereference.of.nullable" message).
     if (treeReceiver.hasAnnotation(NULLABLE) || recvAnnos.contains(MONOTONIC_NONNULL)) {
       return;
     }
   }
   super.checkMethodInvocability(method, node);
 }