The following malformed @GuardedBy expression results in an compile error on the package statement:
package example;
import javax.annotation.concurrent.GuardedBy;
public class IllegalStartOfExpression {
@GuardedBy("itself (synchronized blocks)")
int field;
}
Compile output with options.errorprone.warn("GuardedBy"):
...\src\main\java\example\IllegalStartOfExpression.java:1: error: illegal start of expression
package example;
^
...\src\main\java\example\IllegalStartOfExpression.java:7: warning: [GuardedBy] Invalid @GuardedBy expression: could not resolve guard
int field;
^
(see https://errorprone.info/bugpattern/GuardedBy)
1 error
1 warning
The first error is very misleading due to the unrelated source location.
ErrorProne version: 2.42.0