[ 
https://issues.apache.org/jira/browse/VELOCITY-761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12893542#action_12893542
 ] 

William R. Zwicky commented on VELOCITY-761:
--------------------------------------------

I found a related issue.  I'm trying to make get("property") work, and it has 
the same restriction -- If the class is not public, the method is not visible.  
Since an instance of this class has been placed directly into the Velocity 
context, it seems very odd when methods go missing like this.  Velocity should 
either allow access to all public methods, or crash when the class is not 
public.

You also need a section in the documentation on how to build a context object, 
collecting into one place all the ways properties can be accessed.  This would 
be a good place to document these public/non-public rules.

Below is the class I'm trying to use.  It currently hides inside 
VelocityGetter.java, thus can't be public.

class MapList<K,V> extends AbstractList<V> {
    private Map<K,Integer> map;
    private List<V> values;

    public MapList(List<K> schema) {
        map = new HashMap<K, Integer>();
        for(int i=0; i<schema.size(); i++)
            map.put(schema.get(i), i);
    }

    public MapList(List<K> schema, List<V> values) {
        this(schema);
        this.values = values;
    }

    // === List interface === //

    @Override
    public V get(int index) {
        return values.get(index);
    }

    @Override
    public int size() {
        return values.size();
    }
    
    @Override
    public V set(int index, V value) {
        return values.set(index,value);
    }
    
    // === Extra Magic === //

    public void setValues(List<V> values) {
        this.values = values;
    }
    
//    public V get(K key) {
//        return values.get(map.get(key));
//    }
    
    public String get(String key) {
        return (String) values.get(map.get(key));
    }
}


> Can not reference a property declared in a super-interface and implemented in 
> a non-public class
> ------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-761
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-761
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.3
>            Reporter: Charles Miller
>
> Consider the following:
> public interface MyUser extends java.security.Principal { 
>      String getEmailAddress();
>  }
> class MyUserImpl implements MyUser {
>     public String getName() { ... }
>     public String getEmailAddress() { ... }
> }
> If I put a MyUserImpl in my Velocity context, $user.emailAddress will 
> resolve, but $user.name will not.
> This is a problem with ClassMap#createMethodCache(). It ignores methods 
> declared on the MyUserImpl class because the class is non-public, and it only 
> looks up one level in the Interface hierarchy for methods defined on 
> interfaces: so it will go up as far as the MyUser interface but not as far as 
> the Principal interface.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to