I have classes PrimitiveProperty
and ComplexProperty
and the interface Property
. I want to create an implementation of Property which enforces an empty unmodifiable Set of Property
instances as return value of Property.getProperties
, e.g.
public interface Property {
Set<Property> getProperties();
}
public class ComplexProperty implements Property {
private Set<Property> properties;
//getter overrides the interface method
}
public class PrimitiveProperty implements Property {
private final static Set<Property> EMPTY_PROPS = Collections.unmodifiableSet(new HashSet<Property>(1));
@Override
public Set<Property> getProperties() {
return EMPTY_PROPS;
}
}
With Glassfish 4.0 and I'm getting
java.lang.IllegalAccessException: Class javax.el.ELUtil can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
when I access the property in the leaf
attribute of a Richfaces tree
, e.g.
<r:tree id="aTree"
toggleType="ajax" var="item" >
<r:treeModelRecursiveAdaptor roots="#{aCtrl.roots}"
nodes="#{item.properties}" leaf="#{item.properties.isEmpty()}">
<r:treeNode>
#{item.name}
</r:treeNode>
<r:treeModelAdaptor nodes="#{item.properties}" leaf="#{item.properties.isEmpty()}"/>
</r:treeModelRecursiveAdaptor>
</r:tree>
The issue disappears if I make the EMPTY_PROPS
constant modifiable (by assigning an instance of HashSet
instead of the return value of Collections.unmodifiableSet
) which is not my intention.
Is it possible to achieve what I want to do? Do I have to invent or use an implementation of what Collections$UnmodifiableCollection
('s subclasses) do(es) which is compatible with the JSF access needs?
Arrays#asList
utility, which returns an unmodifiableList
quite frequently, with no problem. Don't know why you have that error for theSet
. – Improvised