groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7916) MissingPropertyException when accessing a static inner class member from a sub class
Date Fri, 26 Aug 2016 06:29:20 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7916?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15438543#comment-15438543
] 

ASF GitHub Bot commented on GROOVY-7916:
----------------------------------------

Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/397#discussion_r76369713
  
    --- Diff: src/main/org/codehaus/groovy/control/ResolveVisitor.java ---
    @@ -852,6 +858,21 @@ protected Expression transformPropertyExpression(PropertyExpression
pe) {
             return ret;
         }
     
    +    private boolean isVisibleNestedClass(ClassNode type, ClassNode ceType) {
    +        if (!type.isRedirectNode()) return false;
    +        ClassNode redirect = type.redirect();
    +        // public or private
    +        if (Modifier.isPublic(redirect.getModifiers()) || Modifier.isProtected(redirect.getModifiers()))
return true;
    +        // package local
    +        PackageNode classPackage = ceType.getPackage();
    +        PackageNode nestedPackage = redirect.getPackage();
    +        if ((redirect.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | Modifier.PRIVATE))
== 0 &&
    +                ((classPackage == null && nestedPackage == null) ||
    +                        classPackage != null && nestedPackage != null &&
classPackage.equals(nestedPackage)))
    +            return true;
    +        return false;
    --- End diff --
    
    Comment says package local but it could be private at this point.  If you added an early
exit `if (Modifier.isPrivate(redirect.getModifiers()) return false;` above the comment this
would be package-private and the modifier check could be eliminated.
    
    If that's the case then the return could be simplified:
    
    ```
    return (classPackage == null && nestedPackage == null) || 
             (classPackage != null && classPackage.equals(nestedPackage))
    ```
    
    I notice that `PackageNode` doesn't implement `equals` so it will end up being an `==`
check.  I'm not that familiar with how the AST is built and if the same `PackageNode` is used
for a given name so just wanted to bring that up.


> MissingPropertyException when accessing a static inner class member from a sub class
> ------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7916
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7916
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator
>    Affects Versions: 2.4.7
>            Reporter: Caleb Ott
>            Assignee: Paul King
>
> Run the following code in groovy to get the error.
> {code:java}
> class Base {
>     static class Inner {
>         static final String CONST = "Hello World";
>     }
> }
> class Derived extends Base {
>     // empty for this example
> }
> println Derived.Inner.CONST
> {code}
> Error:
> {code}
> Caught: groovy.lang.MissingPropertyException: No such property: Inner for class: Derived
> groovy.lang.MissingPropertyException: No such property: Inner for class: Derived
> {code}
> This code can be easily converted to Java and in Java everything works as it should.
> GROOVY-7762 seems to be a related issue.
> I've verified the issue is on this line...
> {code}println Derived.Inner.CONST{code}
> ...because I tried writing the two classes in Java and still have the same issue.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message