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

Reimplement reporting error and warning count when a compilation error happens #29183

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hegyibalint
Copy link
Member

@hegyibalint hegyibalint commented May 16, 2024

When the new problem reporting framework was introduced, we didn't yet implement the error counters.

E.g., the following output from javac has a count at the end (note on the bottom the counters)

Test.java:4: warning: [cast] redundant cast to int
        int value = (int)1;
                    ^
Test.java:5: error: int cannot be dereferenced
        return value.toString();
                    ^
1 error
1 warning

This PR adds these counters back.

@hegyibalint hegyibalint requested a review from a team as a code owner May 16, 2024 13:03
@hegyibalint hegyibalint requested a review from big-guy May 16, 2024 13:03
@hegyibalint hegyibalint changed the title bhegyi/problems/java-compile/emit-error-count Reimplement reporting error and warning count when a compilation error happens May 16, 2024
@hegyibalint hegyibalint requested a review from a team May 16, 2024 13:11
@hegyibalint hegyibalint added a:regression This used to work in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures labels May 16, 2024
@hegyibalint hegyibalint added this to the 8.9 RC1 milestone May 16, 2024
@hegyibalint hegyibalint linked an issue May 16, 2024 that may be closed by this pull request
@hegyibalint hegyibalint linked an issue May 17, 2024 that may be closed by this pull request
@hegyibalint hegyibalint linked an issue May 17, 2024 that may be closed by this pull request
@hegyibalint hegyibalint linked an issue May 17, 2024 that may be closed by this pull request
Copy link
Member

@donat donat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have only a few questions for my own education and some naming/documentation-related requests.

Comment on lines 86 to 110
/**
* This method is based on {JavaCompiler#printCount()}
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ The javadoc should state the following:

  • functionality: this method prints the number of warnings / errors to the standard output
  • intent: when there's no diagnostic listener attached to the compiler object, the number of warnings/errors are part of the putput. Since we have a listener attached, the output changed. Calling this method makes restores compatiblity with the original output
  • source: the method implementation is based on {JavaCompiler#printCount()}.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added further documentation

@@ -63,6 +63,7 @@ public WorkResult execute(JavaCompileSpec spec) {
ApiCompilerResult result = new ApiCompilerResult();
JavaCompiler.CompilationTask task = createCompileTask(spec, result);
boolean success = task.call();
diagnosticToProblemListener.reportDiagnosticCounts();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Will we hit this code path when we do joint Java-Groovy compilation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new integration test verifying this

* /.../Bar.java:10: warning: [cast] redundant cast to String
* String s = (String)"Hello World";
* ^
* 1 error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to validate: do we have coverage when we have 0 errors and/or 1 warnings on the output?

@donat donat force-pushed the bhegyi/problems/java-compile/emit-error-count branch from 387f400 to 193c3f7 Compare May 30, 2024 12:15
@donat
Copy link
Member

donat commented May 30, 2024

@bot-gradle test this

@bot-gradle
Copy link
Collaborator

I've triggered the following builds for you. Click here to see all build failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:regression This used to work in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem-reporting capable compilation doesn't emit error count
4 participants