Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatalOptionalError causes SuppressWarnings on statements to be ignored #1282

Open
patrick96 opened this issue Aug 11, 2023 · 0 comments
Open

Comments

@patrick96
Copy link

This corresponds to the Bug 516289 on the old Bugzilla, which still occurs on newer versions

It seems that the org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled causes the compiler to ignore statement scope @SuppressWarnings annotations.

This still happens today, tested on the following versions:

bad.prefs:

org.eclipse.jdt.core.compiler.codegen.targetPlatform=20
org.eclipse.jdt.core.compiler.compliance=20
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.rawTypeReference=error
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=enabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.source=20

Test.java:

public class Test {
    public static void main(String[] args) {
        @SuppressWarnings("rawtypes")
        Class<? extends Enum> enumClass = null;
        System.out.println(enumClass);
    }
}
$ java -jar ecj-4.28.jar -properties bad.prefs Test.java && java Test
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
        Enum is a raw type. References to generic type Enum<E> should be parameterized

        at Test.main(Test.java:4)

Expected Behavior

The program compiles without warnings or errors and runs to completion while printing null.

Workarounds

  • This does not happen if the annotation appears on the method instead of the statement, so moving such annotation up to the method scope would work.
  • Disabling fatalOptionalError

Additional Context

$ java -version
openjdk version "20.0.2" 2023-07-18
OpenJDK Runtime Environment (build 20.0.2+9-Ubuntu-0ubuntu123.04)
OpenJDK 64-Bit Server VM (build 20.0.2+9-Ubuntu-0ubuntu123.04, mixed mode, sharing)

I have been playing around and digging into the code and I don't see what fatalOptionalError is actually supposed to be doing. From my understanding, problems set to "error" in the properties file are treated as optional errors (and in addition as fatal if fatalOptionalError is set) (CompilerOptions#getSeverity).

Excerpt from the documentation of fatalOptionalError in JavaCore.java:

When disabled, optional errors are only considered as warnings, still carrying an error indication to make them more severe. Note that by default, optional errors are not fatal. Non-optional errors are always fatal.

I understand this as meaning that fatalOptionalError=disabled (the default) causes the compilation to succeed even if these optional errors occur and to print a non-fatal error.
In practice, I have not found situation where this happens, if such an error occurs, the compilation fails as well (take for instance the code above without the SuppressWarnings annotation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant