core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableChecker.java
private Description handleAnonymousClass(
      ClassTree tree, VisitorState state, ImmutableAnalysis analysis) {
    ClassSymbol sym = getSymbol(tree);
    Type superType = immutableSupertype(sym, state);
    if (superType == null) {
      return NO_MATCH;
    }

    if (handleAnonymousClasses) {
      checkClosedTypes(tree, state, superType.tsym, analysis);
    }
    // We don't need to check that the superclass has an immutable instantiation.
    // The anonymous instance can only be referred to using a superclass type, so
    // the type arguments will be validated at any type use site where we care about
    // the instance's immutability.
    //
    // Also, we have no way to express something like:
    //
    // public static <@Immutable T> ImmutableBox<T> create(T t) {
    //   return new ImmutableBox<>(t);
    // }
    ImmutableSet<String> typarams = immutableTypeParametersInScope(sym, state, analysis);
    Violation info =
        analysis.areFieldsImmutable(
            Optional.of(tree),
            typarams,
            ASTHelpers.getType(tree),
            (t, i) -> describeAnonymous(t, superType, i));
    if (!info.isPresent()) {
      return NO_MATCH;
    }
    return describeAnonymous(tree, superType, info).build();
  }
/** Check anonymous implementations of {@code @Immutable} types. */
Check anonymous implementations of   types.
Check anonymous implementations of types .
private Description handleAnonymousClass(
      ClassTree tree, VisitorState state, ImmutableAnalysis analysis) {
    ClassSymbol sym = getSymbol(tree);
    Type superType = immutableSupertype(sym, state);
    if (superType == null) {
      return NO_MATCH;
    }
    if (handleAnonymousClasses) {
      checkClosedTypes(tree, state, superType.tsym, analysis);
    }
     Also, we have no way to express something like:
     public static <@Immutable T> ImmutableBox<T> create(T t) {
       return new ImmutableBox<>(t);
     }
    ImmutableSet<String> typarams = immutableTypeParametersInScope(sym, state, analysis);
    Violation info =
        analysis.areFieldsImmutable(
            Optional.of(tree),
            typarams,
            ASTHelpers.getType(tree),
            (t, i) -> describeAnonymous(t, superType, i));
    if (!info.isPresent()) {
      return NO_MATCH;
    }
    return describeAnonymous(tree, superType, info).build();
  }
private Description handleAnonymousClass ( ClassTree tree , VisitorState state , ImmutableAnalysis analysis ) { ClassSymbol sym = getSymbol ( tree ) ; Type superType = immutableSupertype ( sym , state ) ; if ( superType == null ) { return NO_MATCH ; } if ( handleAnonymousClasses ) { checkClosedTypes ( tree , state , superType . tsym , analysis ) ; } ImmutableSet < String > typarams = immutableTypeParametersInScope ( sym , state , analysis ) ; Violation info = analysis . areFieldsImmutable ( Optional . of ( tree ) , typarams , ASTHelpers . getType ( tree ) , ( t , i ) -> describeAnonymous ( t , superType , i ) ) ; if ( ! info . isPresent ( ) ) { return NO_MATCH ; } return describeAnonymous ( tree , superType , info ) . build ( ) ; }
Check anonymous implementations of {@code @Immutable} types.
Check anonymous implementations of { @code @Immutable } types .
// We don't need to check that the superclass has an immutable instantiation. // The anonymous instance can only be referred to using a superclass type, so // the type arguments will be validated at any type use site where we care about // the instance's immutability. // // Also, we have no way to express something like: // // public static <@Immutable T> ImmutableBox<T> create(T t) { //   return new ImmutableBox<>(t); // }