vendredi 21 août 2015

Reflection : The Enum is Public so is The method then Why IlegalAccessException Is Coming?

Please be patient with me while I try to give as much information as possible with me.

I am getting below exception in my code randomly and not always :

ERROR CACHE-SELECT 2015-08-20 11:19:00,822 nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'table.selectQuerySuffix'. Cause: org.apache.ibatis.ognl.OgnlException: selectQuerySuffix [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class com.dclear.cmn.core.cache.CacheEnum$4 with modifiers "public"] - 

The Enum defined is as following :

public enum CacheEnum {

DD_FEED_FIELD_NF_MAP(Schema.MYSCHEMA, SchemaName.MYSCHEMA, true, ID1, ID2, ID3) {
    @Override
    public String getSelectQuerySuffix() {
        return "";
    }
}

private CacheEnum(Schema schema, SchemaName schemaName, boolean customQuery, ColumnEnum... columns) {
    this.schema = schema;
    this.schemaName = schemaName;
    this.columnNames = columns;
    this.customQuery = customQuery;
}

}

'table.selectQuerySuffix' is defined in MyBatis file to put query suffix. And at runtime it is passed as "" (refer overridden method getSelectQuerySuffix())

This issue is not always coming...I have read that

An IllegalAccessException is thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructor.

But if the issue was coming because constructor CacheEnum is private, why is it not always coming? If not then what is the issue behind it? What am I missing here?





Aucun commentaire:

Enregistrer un commentaire