Skip to content

"illegal start of expression" compile error with malformed @GuardedBy #5454

@jhonnen

Description

@jhonnen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions