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

[android] Check AppCompatActivity classes with CallSuperFirst and CallSuperLast rules #171

Closed
wants to merge 1 commit into from
Closed

[android] Check AppCompatActivity classes with CallSuperFirst and CallSuperLast rules #171

wants to merge 1 commit into from

Conversation

maksim-m
Copy link

@maksim-m maksim-m commented Dec 18, 2016

Check AppCompatActivity classes (activities that use the support library) with CallSuperFirst and CallSuperLast rules

@maksim-m maksim-m changed the title Check AppCompatActivity classes with CallSuperFirst and CallSuperLast… Check AppCompatActivity classes with CallSuperFirst and CallSuperLast rules Dec 18, 2016
@maksim-m maksim-m changed the title Check AppCompatActivity classes with CallSuperFirst and CallSuperLast rules [android] Check AppCompatActivity classes with CallSuperFirst and CallSuperLast rules Dec 18, 2016
@jsotuyod jsotuyod self-assigned this Dec 18, 2016
@jsotuyod jsotuyod added the a:bug PMD crashes or fails to analyse a file. label Dec 18, 2016
@jsotuyod jsotuyod added this to the 5.4.4 milestone Dec 18, 2016
@jsotuyod
Copy link
Member

Thanks for your contribution. This seems great at first sight. I'll add to my review backlog.

@jsotuyod
Copy link
Member

Just one comment though, the rule would work just fine as is with AppCompatActivity and FragmentActivity provided you run pmd with a complete auxclasspath. Type resolution can detect types even if extension is indirect. We can add a bunch of these cases to help people not configuring auxclasspath properly, but it won't handle indirect extension unless you use auxclasspath (A extends B, which extends AppCompatActivity).

To help in setting up the auxclasspath properly, I suggest you use / take a look at this gradle plugin

@maksim-m
Copy link
Author

@jsotuyod thanks for the reply. I'll take a look at the plugin.

@jsotuyod
Copy link
Member

I'm on two minds regarding this. We could merge this and even add the case for FragmentActivity and people would see less False Negatives regardless of configuration, but I feel that would be hiding the real issue, which is the lack of / misconfigured auxclasspath. This is something I've questioned in another ocassion

I am certain we need to be much more verbose regarding this, maybe even go as far as including missing classes on reports to help people figure out what is missing exactly, just as FindBugs does, although that may produce some misleading messages with generics (we would need to asses / improve that), but even if so, it would still be better than the current situation where people can't even tell there is something amiss in their setup.

Both the maven plugin and Gradle configure auxclasspath properly out of the box. Android Gradle projects (en even Java ones running old Gradle versions) can use my gradle plugin to have it working and properly configured out of the box. Maybe it's time to just push for it. What do you think @adangel ?

@adangel
Copy link
Member

adangel commented Jan 4, 2017

@jsotuyod Regarding auxclasspath - I think, this is the direction, we should be heading towards: Making a properly configured auxclasspath a requirement for using rules which need typeresolution. At the moment these rules are still executed, but most types are null then - which leads to false positives/negatives.
In 5.6.0 we can change the behavior slightly - if no auxclasspath is configured, we disable all rules, that need typeresolution and in that case, we can print out a warning (or even fail hard...).
You're right, maven and gradle already configure this correctly and execute PMD in a phase, where we have the compiled classes available. For ant users, we need to provide better documentation on typeresolution, auxclasspath and how to setup PMD for a project.
I recently read an older comment about typeresolution: the typresolution ruleset was intended to be temporarily and eventually the rules should replace the existing rules (e.g. CloneMethodMustImplementCloneable).
I assume, it is a bit more tricky to detect an incomplete/wrong auxclasspath setting - but it should still be possible: E.g. we could assume, that we need to be able to resolve all references. If we find any type to be null after the type resolution was done for a compilation unit, we could stop PMD and output the unknown class name.

@jsotuyod
Copy link
Member

jsotuyod commented Jan 5, 2017

E.g. we could assume, that we need to be able to resolve all references. If we find any type to be null after the type resolution was done for a compilation unit, we could stop PMD and output the unknown class name.

@adangel I'd not implement it this way. Such a fail fast approach would produce a harder to fix scenario such as "hey, you missed junit", "now you are missing apache commons", "hey, do you know where is guava?". I'd personally favor a single failure with all missing classes.

I'm in for disabling type resolution rules when auxclasspath is not configured, though we may consider a hard fail on such scenarios (misconfigured). I believe right now most people are falling into this scenario rather than missing classes.

Finally, we certainly need to improve the documentation on the type resolution rules. We don't even mention auxclasspath right now https://pmd.github.io/pmd-5.5.2/pmd-java/rules/index.html#Type_Resolution

Finally killing the type resolution ruleset would be awesome

As is, I'd probably reject this PR, and create some tasks to address these 3 points on their owm (documentation, missing auxclasspath with typeresolution, missing classes).

I'd suggest the changes being impacted on 5.6.0 only aince they would be breaking changes.

@jsotuyod jsotuyod added a:suggestion An idea, with little analysis on feasibility, to be considered and removed a:bug PMD crashes or fails to analyse a file. labels Jan 6, 2017
@jsotuyod jsotuyod mentioned this pull request Jan 17, 2017
5 tasks
@maksim-m
Copy link
Author

maksim-m commented Jan 17, 2017

Thanks for the discussion. I close the PR.

@maksim-m maksim-m closed this Jan 17, 2017
@maksim-m maksim-m deleted the android_AppCompatActivity branch January 17, 2017 21:31
@jsotuyod
Copy link
Member

@maksim-m thank you for bringing this up! It was certainly a useful discussion, and I'll be working to address these items.

I hope the Gradle plugin I pointed to you has helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:suggestion An idea, with little analysis on feasibility, to be considered
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants