Skip to content

Restore the -Xlint category on in-process javac warnings - #515

Merged
slachiewicz merged 1 commit into
masterfrom
agent/javac-lint-category
Sep 9, 2026
Merged

slachiewicz merged 1 commit into
masterfrom
agent/javac-lint-category

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Warnings compiled in process lost the bracketed lint category javac prints in front of them, so [deprecation] or [module] never reached the build log and the reader had no way to tell which -Xlint: flag or @SuppressWarnings key would silence the warning. Fixes #183.

This is a back-end parity defect rather than a JDK limitation. The forked compiler already keeps the category because it parses javac's own output — ErrorMessageParserTest pins [deprecation] ThreadSafeClientConnManager … — which is why <forceJavacCompilerUse>true</forceJavacCompilerUse> was the workaround given on the issue. Only the javax.tools path drops it.

Diagnostic.getMessage(Locale) omits the category by design (JDK-8292634, closed as not an issue), and getCode() carries a resource key such as compiler.warn.raw.class.use that does not map onto a lint category. toString() is the only place it survives, so lintCategoryOf reads it back from there.

The category is located by anchoring on the message text rather than on the warning: marker in front of it: the marker is localised (警告:[deprecation], as in the existing parser tests) while the category never is. Only the first line of the message is used as the anchor, because a wrapped message continues below the source line and caret and is not contiguous in the rendering. A bracket that merely sits in a path is rejected — it has to be the last thing before the message and a single token.

The missing-warnings IT is the reporter's own case, but it sets forceJavacCompilerUse, which is exactly why it passed while the bug was open. A missing-warnings-in-process sibling now covers the default path; without the change it fails with the symptom from the issue, module-info.java:[2,32] module not found: someOtherModule.

Not addressed here: forked and in-process message bodies still differ where javac abbreviates a type in its console output (found raw type: List) that the API spells out (found raw type: java.util.List). The new unit test compares the category and the line, not the body.

Verified: mvn install on JDK 25, whole reactor green, 12 ITs pass; reverting the prepend in JavaxToolsCompiler fails the new IT and the new parity test.

This change was created with AI assistance.

javac prints [deprecation] and friends only in Diagnostic.toString();
getMessage() leaves it out and getCode() never carried it, so the category
is read back off the rendering. Do not simplify that to getMessage() again:
the forked compiler keeps the category because it parses javac's output, and
the two back-ends have to agree.
@slachiewicz slachiewicz added bug Something isn't working java Pull requests that update Java code labels Sep 9, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review September 9, 2026 11:44
@slachiewicz
slachiewicz merged commit da2af22 into master Sep 9, 2026
36 checks passed
@slachiewicz
slachiewicz deleted the agent/javac-lint-category branch September 9, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output information needed to suppress Xlint warnings

1 participant