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

walkmod execution to remove dead code #1957

Closed
wants to merge 5 commits into from
Closed

walkmod execution to remove dead code #1957

wants to merge 5 commits into from

Conversation

rpau
Copy link

@rpau rpau commented Dec 20, 2015

Hi,

I have executed walkmod, an open source tool to apply code conventions. In this case, I just tried to remove dead code in the core module. After executing it, the results are as follows:

  • Deletes of unused imports
  • Deletes of private variables and fields
  • Deletes of some private "readResolve" methods because classes are not Serializable.

Moreover, executing walkmod I have discovered some dependency conflicts that I have specified as "exclusions" and a missing runtime dependency.

Let me know if the results seem interesting to you :) and thank you for your time.

@KostyaSha
Copy link
Member

👎 even if classes are not marked with Serializable they are serialised/deserialized with XStream, this change will break jenkins.
👎 for doing code clean-ups without understanding jenkins code and without having defined rules before to exclude next possible changes.
@rpau Please join discussion https://groups.google.com/d/topic/jenkinsci-dev/8fjvXGYbFJ4/discussion

@rpau
Copy link
Author

rpau commented Dec 20, 2015

Thank you for your comments

  1. Then, there is a problem: Some classes should implement Serializable and they don't. Right? I can add it as a rule.

  2. Sorry, but I don't understand the second issue. What do you mean "without having defined rules before to exclude next possible changes"? Do you prefer a PR just with the walkmod configuration and not the corrected code?

  3. Thank you for the link. I will be a pleasure to participate :).

@KostyaSha
Copy link
Member

Sorry, i wasn't clear enough.

  • for "2)" i mean coding style changes should go to email discussion. As there is still no agreement in project. Changes for imports * to single lines and again may happen always and coding style should be defined before.
  • walkmod usage discussion may happen here

@imod
Copy link
Member

imod commented Dec 21, 2015

I'm not yet sure if I think this is a good thing or not, but its an interesting idea!
Definitively wrong is the remove of all readResolve() - this will break quite a bit of backward compatibility

@KostyaSha
Copy link
Member

@imod @oleg-nenashev and i do periodic static analysing verifications with coverity (that is the most powerful as it closed source). Code styling under discussion. Dependency changes under question as it may change versions and break plugins. PR build fails because of license(?).

@daniel-beck
Copy link
Member

@rpau
Copy link
Author

rpau commented Dec 21, 2015

Thank your for all your comments :) I really appreciate them.

  1. What am I asking if there is an specific criteria to define if some classes should implement Serializable. What do you prefer? Add the implements Serializable or just ignore those readResolve? Two options are valid for me to adapt your walkmod configuration and plugins. Other practices such as add @Override can be added. If you are interested in the autofix of an specific Checkstyle config, I can do too.

  2. This PR fails because there is a test that produces a null pointer, but this test also failed before I applied the walkmod changes.

  3. Dependency changes are because there are multiple dependencies with different versions. However, the version choosen by maven is the same. The other one, is just a "runtime" dependency which may also appear in some of your executions. I have solved it because, walkmod uses Java reflection and with one of your classes, it produces an error because there is a dependency with a class of the introduced library.

  4. Walkmod can be executed by developers before pushing code (and even just for your modified files), like PMD or CheckStyle from their local machine. Moreover, you could receive periodic PR with the suggested changes by walkmodhub (walkmod service) and then decide to accept or reject changes. Actually, I prefer to discuss what are your conventions and have a valid "execution" for this project :)

@rpau
Copy link
Author

rpau commented Dec 23, 2015

Hi, I have upgraded the walkmod configuration and the final result. Now, the readResolve methods are not removed. Can you take a look if the rest is ok for you?

Thanks

/**
* Lazily computed set of labels from {@link #label}.
*/
private transient volatile Set<Label> labels;
Copy link
Member

Choose a reason for hiding this comment

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

Should be protected instead of private. But probably may cause compatibility issues.

Copy link
Author

Choose a reason for hiding this comment

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

Perfect :-) ! I can change it

Copy link
Member

Choose a reason for hiding this comment

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

I fear you can't touch it because it may cause issues as i definitely remember that using labels cache for slaves. Feel free to investigate cloud plugins.

Copy link
Author

Choose a reason for hiding this comment

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

Jenkins allow that cloud plugins are able to access to this "private" field using reflection? Otherwise, they can't access to this field.

Copy link
Member

Choose a reason for hiding this comment

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

java code - not, groovy - whatever you want.

Copy link
Author

Choose a reason for hiding this comment

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

Ok ok, thanks

Copy link
Author

Choose a reason for hiding this comment

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

I have found plugins with groovy code that reference this property. I will add an exclude rule to avoid remove this property.

Copy link
Member

Choose a reason for hiding this comment

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

@rpau and now image that not all plugins under jenkinsci github account are hosted. Any clean-up change adds probability in compatibility breakage that jenkins is keeping so many years. You can propose such step for 2.0 as it will expect breakages. Removing unused imports imho relates to coding style (thread that i started in dev list).

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I understand it, but I think that it is consequence of a direct binding of the plugins with the internal implementation details. I agree on applying these kind of changes in the 2.0 version.

Removing unused imports or variables is part of the coding style, but also any of the changes in the Java source file as well. However, in contrast with the field and method declarations, it can't break plugins.

@KostyaSha
Copy link
Member

Any removed method can be accessed from groovy.

@KostyaSha
Copy link
Member

Could you provide diff of dependencies before this PR and after?

@rpau
Copy link
Author

rpau commented Dec 23, 2015

So,

  1. I need to check if the removed methods or fields are used by any cloud plugin, right?
  2. What do you mean with the diff of dependencies - create a different PR ? You can compare the pom.xml in this PR.

@KostyaSha
Copy link
Member

  1. I need to check if the removed methods or fields are used by any cloud plugin, right?

Wait for other reviewers. Keeping in mind that some of already on vacation, it may happen that PR wouldn't be merged until january.

  1. pom doesn't reflect transitive deps, text diff from mvn dependency tree before and after

@rpau
Copy link
Author

rpau commented Dec 23, 2015

Diff

It includes the new runtime dependency (javarebel-sdk) and the excluded rules for stappler that previously, sends a conflict message.

> [INFO] +- org.zeroturnaround:javarebel-sdk:jar:2.0.2:runtime
73d95
< [INFO] |  \- (org.kohsuke.stapler:stapler:jar:1.140:compile - omitted for conflict with 1.237)
75d96
< [INFO] |  \- (org.kohsuke.stapler:stapler:jar:1.140:compile - omitted for conflict with 1.237)
77d97
< [INFO] |  \- (org.kohsuke.stapler:stapler:jar:1.140:compile - omitted for conflict with 1.237)
79d98
< [INFO] |  \- (org.kohsuke.stapler:stapler:jar:1.140:test - omitted for conflict with 1.237)

@@ -674,7 +674,7 @@ public void renameTo(String newName) throws IOException {

@Override
public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir) throws IOException {
Job newJob = (Job) newItem; // Missing covariant parameters type here.
Copy link
Member

Choose a reason for hiding this comment

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

I thought this comment was related to removed line. I guess it used to check types even if it not used.

Copy link
Author

Choose a reason for hiding this comment

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

But do you think that is makes sense if the parameter is not used?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see any reason to keep this line

Copy link
Member

Choose a reason for hiding this comment

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

Or to be on the safe side assert newItem instanceof Job

<artifactId>javarebel-sdk</artifactId>
<version>2.0.2</version>
<scope>runtime</scope>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

@daniel-beck
Copy link
Member

@KostyaSha

Any removed method can be accessed from groovy.

WDYM? (Is this comment obsolete?)

@rpau
Copy link
Author

rpau commented Jan 12, 2016

Hi, is going to be accepted this pull request? What else is necessary to correct?

Thanks

@KostyaSha
Copy link
Member

@rpau get agreement between contributors, that may end in PR delayed for years.

@KostyaSha
Copy link
Member

WDYM? (Is this comment obsolete?)

Not really, but i'm against removing some code just for analyser until core will have some defined rules. I also don't think that @rpau would be ready to work on any regressions caused but this changes.

Also this PR still doesn't pass verification.

@@ -44,4 +44,3 @@
*/
package hudson.init;

import org.jvnet.hudson.reactor.Task;
Copy link
Member

Choose a reason for hiding this comment

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

Is javadoc navigable after this change?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, because the javadoc only uses a full qualified name

Copy link
Member

Choose a reason for hiding this comment

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

Not all docs using FQDN that depends on IDE settings.

@oleg-nenashev oleg-nenashev added the needs-comments-resolved Comments in the PR need to be addressed before it can be considered for merging label Jul 2, 2016
@oleg-nenashev oleg-nenashev added the unresolved-merge-conflict There is a merge conflict with the target branch. label Jul 2, 2016
@daniel-beck
Copy link
Member

@KostyaSha Any Groovy script wasn't supposed to access private methods in the first place. There has never been a reasonable expectation that we keep compatibility for those.

@oleg-nenashev
Copy link
Member

Any plans to finalize it?

@rpau
Copy link
Author

rpau commented Aug 16, 2016

@oleg-nenashev To finalize the review?

@daniel-beck
Copy link
Member

PR appears to have been abandoned, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-comments-resolved Comments in the PR need to be addressed before it can be considered for merging unresolved-merge-conflict There is a merge conflict with the target branch.
Projects
None yet
6 participants