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

[java] Parser error with private method in nested classes in interfaces #798

Merged
merged 2 commits into from Dec 23, 2017

Conversation

adangel
Copy link
Member

@adangel adangel commented Dec 20, 2017

Fixes #793

@adangel adangel added the a:bug PMD crashes or fails to analyse a file. label Dec 20, 2017
@adangel adangel added this to the 6.0.1 milestone Dec 20, 2017
@jsotuyod
Copy link
Member

jsotuyod commented Dec 20, 2017

@adangel if the flag is reset after finding a nested enum / class / anonymous class, doesn't is miss any following up private methods?

ie:

public interface InterfaceWithInnerClass {

    Object FOO = new Object() {
        private void privateMethod() { }
    };

    class InnerClass {
        private void privateMethod() { }
    }
 
     enum InnerEnum {
         VALUE;
         private void privateMethod() { }
     }

    private void foo() { } // bad, but not reported as the flag has been reset 3 times already
 }

It seems like we need to have a stack of flags, pushing a new value each time we enter a new class / interface / annotation / enum / anonymous class; and poping as we leave... are my assumptions correct?

@jsotuyod jsotuyod self-assigned this Dec 20, 2017
@adangel adangel added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Dec 21, 2017
…es in interfaces

*   Remember old state to allow nesting
*   Fix ASTMethodDeclaration.isInterfaceMember
*   Extended tests
@adangel adangel removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Dec 22, 2017
@adangel
Copy link
Member Author

adangel commented Dec 22, 2017

@jsotuyod You are right - nesting wasn't supported. I've fixed the issue and added an additional test case. I didn't yet use Stack<Boolean>, but just remembered the old value in the current method stack the parser is executing.
I can rewrite the logic using a separate stack, if this seems better.

@vanniktech
Copy link
Contributor

Whops sorry for that. I messed up my tabs.

@jsotuyod jsotuyod changed the title Fixes #793 [java] Parser error with private method in nested classes … [java] Parser error with private method in nested classes in interfaces Dec 22, 2017
@jsotuyod
Copy link
Member

@adangel amazing, it looks good now. I'll do some manual testing myself and merge if I find no further issues.

@jsotuyod jsotuyod merged commit 109f458 into pmd:master Dec 23, 2017
@adangel adangel deleted the issue-793 branch December 23, 2017 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants