Skip to content

Issue #5337: Deprecate AutomaticBean#12213

Merged
rnveach merged 1 commit into
checkstyle:masterfrom
stoyanK7:issue/5337-rename-AutomaticBean
Mar 23, 2023
Merged

Issue #5337: Deprecate AutomaticBean#12213
rnveach merged 1 commit into
checkstyle:masterfrom
stoyanK7:issue/5337-rename-AutomaticBean

Conversation

@stoyanK7

Copy link
Copy Markdown
Collaborator

Resolves #5337

First step of deprecating AutomaticBean and moving to AbstractAutomaticBean.

Comment thread pom.xml Outdated
*/
// -@cs[AbstractClassName] We can not break compatibility with previous versions.
@Deprecated(since = "10.3.4")
public abstract class AutomaticBean

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#5337 (comment)
#5337 (comment)

Why can't we rename AutomaticBean to AbstractAutomaticBean and create a new AutomaticBean that extends AbstractAutomaticBean but is marked as deprecated?

With this type of make up, we won't need additional "ifs" and current code can just swap to AbstractAutomaticBean as both extend it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I see no problem. Never would have came up with this though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@stoyanK7 Let us know when this is done.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@rnveach it is. I'm trying to address the failing CI jobs and I will tag you then

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@rnveach I have kept the enum in the old class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@rnveach

rnveach commented Sep 21, 2022

Copy link
Copy Markdown
Contributor

CI Failure:
https://github.com/checkstyle/checkstyle/actions/runs/3092656103/jobs/5004176175

Caused by: java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.api.AutomaticBean$OutputStreamOptions
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:239)
    at org.apache.maven.plugins.checkstyle.AbstractCheckstyleReport.getConsoleListener (AbstractCheckstyleReport.java:685)

https://github.com/apache/maven-checkstyle-plugin/blob/627fa4f684866a579f2c105fcc1dbf3ed776daa8/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java#L63
https://github.com/apache/maven-checkstyle-plugin/blob/627fa4f684866a579f2c105fcc1dbf3ed776daa8/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java#L686

@rnveach

rnveach commented Sep 21, 2022

Copy link
Copy Markdown
Contributor

It looks like this usage is preventing us from fully separating the classes like planned as we are completely reliant on this maven plugin and have not severed times with them. #11602

Unless there is any other ideas, I think we will have to have a copy of OutputStreamOptions in both classes, with everything being marked deprecated in the old class.
Edit: Since its an enum, duplicating the class means we have 2 different classes and would have to quadruple method signatures. We may be forced to keep the enum in the deprecated class until it can be completely removed.

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

Not sure why No Error Test (openjdk11, fast pool) - CMD=.ci/validation.sh no-error-methods-distance complains.
https://github.com/sevntu-checkstyle/methods-distance/blob/412c3bff7258daf7683081f72dd1bf9d8aaf622a/methods-distance/src/test/java/com/github/sevntu/checkstyle/domain/BaseCheckTestSupport.java#L132-L136

I think it automatically tries to use AbstractAutomaticBean.OutputStreamOptions instead of AutomaticBean.OutputStreamOptions? Is an explicit import valid solution here?


Should I also deal with Checker-Framework errors? I notice it is still being introduced to the repo.


Pitest / pitest (pitest-api) (pull_request)

Error:  Failed to execute goal org.pitest:pitest-maven:1.9.5:mutationCoverage (default-cli) on project checkstyle: 
Line coverage of 99(661/665) is below threshold of 100 -> [Help 1]

Ran pitest locally and this is the result 650/650, not 661/665 though it fails with same error message.
Screenshot from 2022-09-27 14-14-34

@rnveach

rnveach commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

Should I also deal with Checker-Framework errors?

I am not really a fan of checker, so I would concentrate on it's failures last. It looks like pitest is failing, so I would look at that first.

Not sure why [No Error Test (openjdk11, fast pool) - CMD=.ci/validation.sh no-error-methods-distance]
I think it automatically tries to use AbstractAutomaticBean.OutputStreamOptions instead of AutomaticBean.OutputStreamOptions?
Is an explicit import valid solution here?

I am surprised some import statement is not needed for OutputStreamOptions in this situation. Forcefully adding one gives an error in Eclipse saying the import is never used.

I do think one issue is there are 2 OutputStreamOptions in this PR. I thought we would keep the original enum in the deprecated class and leave it there and not duplicate it until we can full break compatibility as said in #12213 (comment) .

Pitest / pitest (pitest-api) (pull_request)
99(661/665) is below threshold of 100

I don't know why the main report is not reporting anything, but do a scan on uncovered and that will narrow down where you need to look. I was only seeing lines in AbstractAutomaticBean connected to the enum. So I assume that is what it is reporting. Since this connects to my previous statement, lets look into that first and then we can come back to pitest.

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

@rnveach Removed OutputStreamOptions completely from AbstractAutomaticBean. pitest-api seems to be ok.

However, the No Error Test (openjdk11, fast pool) - CMD=.ci/validation.sh no-error-methods-distance problem still persists:

[ERROR] /home/semaphore/checkstyle/.ci-temp/methods-distance/methods-distance/src/test/java/com/github/sevntu/checkstyle/domain/BaseCheckTestSupport.java:[135,56] cannot find symbol
[ERROR]   symbol:   variable OutputStreamOptions

@rnveach

rnveach commented Sep 28, 2022

Copy link
Copy Markdown
Contributor

@stoyanK7 The compilation error changed, it isn't the same issue, so you'll need to look at what we need to do to make it pass. All these compilation errors seem to mean a classpath is changing and the other projects we are compiling can't be changed until this PR is released, so you have to keep the classpaths the same.

@stoyanK7

stoyanK7 commented Sep 29, 2022

Copy link
Copy Markdown
Collaborator Author

@rnveach

I am looking at ClassNotFound failures a few commits ago(before OutputStreamOptions was moved to AutomaticBean).

no-exception-test.sh guava-with-google-checks

java.lang.NoClassDefFoundError: com/puppycrawl/tools/checkstyle/api/AutomaticBean$OutputStreamOptions 01:16
    at org.apache.maven.plugins.checkstyle.AbstractCheckstyleReport.getConsoleListener (AbstractCheckstyleReport.java:685)

We have explicit import at AbstractCheckstyleReport.java#63

no-error-orekit

Caused by: java.lang.NoClassDefFoundError: com/puppycrawl/tools/checkstyle/api/AutomaticBean$OutputStreamOptions 02:10
    at org.apache.maven.plugins.checkstyle.CheckstyleViolationCheckMojo.getConsoleListener (CheckstyleViolationCheckMojo.java:802)

We have explicit import at CheckstyleViolationCheckMojo.java#65

These two and multiple other jobs that have the same errors are now working except no-error-methods-distance because it does not have that explicit import. I do not see another way here.

Besides, there are already multiple explicit imports from com.puppycrawl.tools.checkstyle in BaseCheckTestSupport

@rnveach rnveach self-assigned this Oct 4, 2022
@rnveach

rnveach commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

We have explicit import at CheckstyleViolationCheckMojo.java#65
no-error-methods-distance

The main difference I am seeing between these is that methods-distance extends DefaultLogger while the others just instantiate DefaultLogger. When I modify BaseCheckTestSupport and remove the extension of DefaultLogger it then starts complaining about it doesn't know where OutputStreamOptions comes from.

Like I said, I don't understand how this is all working behind the scenes but this is appears to be how it is working. Feel free to test things out on your local to see how things are behaving and if a resolution can be made.

As a fall back, you can try to add an import to the class and see if it will compile with this PR. In my Eclipse, it tells me its an unnecessary import and we have other static checks that also may flag it as unnecessary and prevent merging that fix.

there are already multiple explicit imports from com.puppycrawl.tools.checkstyle in BaseCheckTestSupport

Because the package name is different, so the imports have to be made explicit. All those classes are being instantiated and not extended which is making OutputStreamOptions behave differently for imports.

=====

The reason why it is "not working" anymore is because DefaultLogger is not extending the class that has the enum, so it is not seeing the enum in its path anymore. The enum has to stay in the same location for other CI items...

I also noticed that the enum is also now being marked as deprecated since the class it comes from, AutomaticBean is deprecated. This is not looking good since this enum is not being deprecated but it appears that way. I am rethinking my earlier decision of not duplicating the enum in the AbstractAutomaticBean. We need somewhere for them to swap to if the enum will have any chance of being deprecated. If we do this, we will need to appease code coverage but all instances should be using the non-deprecated enum. I recommend making something to convert one enum to the other. This will also resolve the methods-distance issue as well.

Let me know if you have any other ideas.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

items:

// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///////////////////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.api;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as we create new class can we move it out of API package, we do not want implementations to be our API.

it might create bad cycle dependency of api package to implementation, but it is fine, it is only for migration period.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do we want it under just com.puppycrawl.tools.checkstyle?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

@rnveach

As a fallback, you can try to add an import to the class and see if it will compile with this PR. In my Eclipse, it tells me its an unnecessary import and we have other static checks that also may flag it as unnecessary and prevent merging that fix.

IntelliJ is okay with this import for me when methods-distance project is under .ci-temp/ folder. Though running mvn package results in build failure:

Tests run: 31, Failures: 30, Errors: 0, Skipped: 1

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for methods-distance-parent 1.0-SNAPSHOT:
[INFO] 
[INFO] methods-distance-parent ............................ SUCCESS [  2.529 s]
[INFO] methods-distance ................................... FAILURE [  1.466 s]
[INFO] methods-distance-web ............................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

Cloning the repo and running it alone fails the same way. Am I missing something? README.md only mentions to clone source and run mvn package.

@rnveach

rnveach commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

Have you tried the other items before the "fallback" one? If the others are not working, please explain why.

@stoyanK7

stoyanK7 commented Oct 13, 2022

Copy link
Copy Markdown
Collaborator Author

Currently testing them, the above one is an experiment as well. Will let you know when done.

@rnveach

rnveach commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

Though running mvn package results in build failure:

This is the command we run in CI. If you still have issues I would need to know what the failure is.
https://github.com/checkstyle/checkstyle/blob/master/.ci/validation.sh#L709-L710

@rnveach

rnveach commented Nov 12, 2022

Copy link
Copy Markdown
Contributor

@stoyanK7 ping

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

On it. Apologies.

Comment on lines +80 to +85
public DefaultLogger(OutputStream outputStream,
AutomaticBean.OutputStreamOptions outputStreamOptions) {
this(outputStream, OutputStreamOptions.values()[outputStreamOptions.ordinal()]);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@rnveach This is the enum conversion in action. We only need to do it here and in XMLLogger, so I think it is okay like that. Or maybe make some util function though it would be temporary until AutomaticBean gets removed. What do you think?

Taken from this StackOverflow answer.


Do you have any ideas on how to tackle the new surviving mutation:

 Source File: "DefaultLogger.java"
Class: "com.puppycrawl.tools.checkstyle.DefaultLogger"
Method: "<init>"
Line Contents: "this(outputStream, OutputStreamOptions.values()[outputStreamOptions.ordinal()]);"
Mutator: "org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator"
Description: "removed call to com/puppycrawl/tools/checkstyle/api/AutomaticBean$OutputStreamOptions::ordinal"
Line Number: 82

ordinal() is essentially swapped with 0 so we get this(outputStream, OutputStreamOptions.values()[0]);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fields that get set depending on value of outputStreamOptions aren't public so we cannot just check them and fail a test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you have any ideas on how to tackle the new surviving mutation:

I would check out #12341 , but I don't seeing regression being helpful for this case where the target of the regression is basically infrastructure related.

You will need to examine the code and the mutation being applied to understand how to kill it.

ordinal

This is such odd code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Made a temporary public method isCloseStream() to kill the mutation.

This is such odd code.

Okay, casting by shared enum value:

this(outputStream, OutputStreamOptions.valueOf(outputStreamOptions.name()));

Done.

@stoyanK7

stoyanK7 commented Feb 18, 2023

Copy link
Copy Markdown
Collaborator Author

Ran pitest-api mode locally. Doesn't show where the uncovered lines are:

[ERROR] Failed to execute goal org.pitest:pitest-maven:1.11.0:mutationCoverage (default-cli) on project checkstyle: Line coverage of 99(538/544) is below threshold of 100 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.pitest:pitest-maven:1.11.0:mutationCoverage (default-cli) on project checkstyle: Line coverage of 99(538/544) is below threshold of 100

Screenshot from 2023-02-19 00-29-31

I assume it is the enum like before?

@rnveach

rnveach commented Feb 19, 2023

Copy link
Copy Markdown
Contributor

@Vyom-Yadav @nrmancuso
https://github.com/checkstyle/checkstyle/actions/runs/4213455949/jobs/7313174365#step:6:365
This PR has a coverage drop but pitest says No new surviving mutation(s) found..

Edit: I will update this with more info.

Line coverage of 99(538/544) is below threshold of 100

We have a line coverage drop, but not a mutation drop (least not failed with). So this is why we have "no new surviving mutations".

For me, master says 640/640.

The report downloaded from the CI does not have 538/544 for line coverage. It says 532/532 and 100%.

The CI report has lost AutomaticBean.java completely. All other classes report the same numbers as master. There is no AbstractAutomaticBean.java listed but it moved outside api package. AutomaticBean is still listed in api but only contains an enum class.

I can confirm CI behavior in my local.

@rnveach

rnveach commented Feb 19, 2023

Copy link
Copy Markdown
Contributor

@stoyanK7 This looks like an issue with pitest. It doesn't report data on AbstractAutomaticBean so it doesn't show up in the report. As such, I think missing code coverage is in that class.

Please report issue to https://github.com/hcoles/pitest/issues/ so we can get their take and look into the class you changed and it's code coverage to show us it is still at 100%.

Also please resolve other CI errors and anything left for this PR.

Edit: AbstractAutomaticBean is no longer in API package. So this is even more confusing, issue needs to be reported to pitest as it isn't making sense to me.

Edit 2: Report doesn't list the remaining AutomaticBean which just contains an Enum inside it. So yea, it seems likely it is what is having issue with line coverage. This still seems like an issue in pitest.

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

@rnveach Most of the checker errors are just old ones that are being moved to AbstractAutomaticBean. Should I bother with fixing those?

@romani

romani commented Feb 25, 2023

Copy link
Copy Markdown
Member

Just reminder that we need compatibility. We need to be sure that sevntu works fine.

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

Sevntu fails because #12755 is waiting to get merged.

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/XMLLogger.java Outdated
@stoyanK7 stoyanK7 requested a review from rnveach March 2, 2023 15:54
@rnveach rnveach assigned romani and unassigned rnveach Mar 5, 2023
@romani

romani commented Mar 19, 2023

Copy link
Copy Markdown
Member

I marked such violations as wontfix
image

@romani

romani commented Mar 20, 2023

Copy link
Copy Markdown
Member

@stoyanK7 , please resolve conflict.

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

@romani Can I resolve this conflict when this PR is approved? This conflict happens almost every day.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see solution backward compatible , that is good.

items:

Comment thread src/test/java/com/puppycrawl/tools/checkstyle/DefaultLoggerTest.java Outdated
Comment thread src/test/java/com/puppycrawl/tools/checkstyle/DefaultLoggerTest.java Outdated
Comment thread pom.xml Outdated
Comment thread config/pmd-main.xml Outdated
Comment thread config/pitest-suppressions/pitest-common-suppressions.xml Outdated
Comment thread config/import-control.xml
@romani

romani commented Mar 20, 2023

Copy link
Copy Markdown
Member

Can I resolve this conflict when this PR is approved?

ok.

@romani romani changed the title Issue #5337: Rename AutomaticBean Issue #5337: Deprecate AutomaticBean Mar 21, 2023

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

last:

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/Main.java Outdated

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok to merge.

All reviewer are mandatory to finish review

@romani romani assigned nrmancuso and unassigned romani Mar 21, 2023
@rnveach rnveach removed their request for review March 21, 2023 15:26

@nrmancuso nrmancuso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few minor items:

Comment thread src/test/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBeanTest.java Outdated
Comment thread config/import-control.xml Outdated
Comment thread config/archunit-store/slices-should-be-free-of-cycles-suppressions
@nrmancuso nrmancuso assigned rnveach and unassigned nrmancuso Mar 23, 2023
@rnveach rnveach merged commit 6a36be8 into checkstyle:master Mar 23, 2023
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

Successfully merging this pull request may close these issues.

Deprecate com.puppycrawl.tools.checkstyle.api.AutomaticBean

4 participants