I have a running application where once I clicked on a 'Edit' link of a table, I'm getting an error in the log of NoSuchMethodError and the control stays in the current page, not proceeding to the edit page.

Below piece of code has been hit while getting the error;

Field[] fields = entityObj.getClass().getDeclaredFields(); 
    for(int i=0;i<fields.length;i++){
        Field field =fields[i];         
        field.setAccessible(true);  
        if(field.getDeclaredAnnotation(EmbeddedId.class)!=null){
            return true;
        }
    }
    return false;

In the above code at the line, if(field.getDeclaredAnnotation(EmbeddedId.class)!=null) I'm getting the particular error.

Also mentioning the log as below;

Caused by: java.lang.NoSuchMethodError: java.lang.reflect.Field.getDeclaredAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
    at com.sprint.neo.querymodel.common.QueryObjectUtil.checkEnitityIsHasEmbeddedId(QueryObjectUtil.java:131)
    at com.sprint.neo.querymodel.common.EntityManager.getEntityObject(EntityManager.java:89)
    at com.sprint.neo.querymodel.common.EntityManager.loadEntityObject(EntityManager.java:72)
    at com.sprint.neo.querymodel.common.EntityManager.entityload(EntityManager.java:60)
    at com.sprint.neo.querymodel.common.EntityManager.loadAndGetEntityObject(EntityManager.java:56)
    at com.sprint.neo.querymodel.common.QueryObjectUtil.getListOfEntityObject(QueryObjectUtil.java:718)
    at com.sprint.neo.querymodel.common.QueryObjectCache.excuteUpdate(QueryObjectCache.java:251)
    at com.sprint.neo.querymodel.common.QueryObjectRow.excuteUpdate(QueryObjectRow.java:298)
    at com.sprint.neo.engine.controller.actions.TaskViewEditAction.edit(TaskViewEditAction.java:83)

The control should proceed to the edit jsp page as all the jsp are implemented correctly. What I'm doubting about the error from the log is that, if any jar file is missing regarding Reflection api. Please suggest me a solution to overcome this problem. Any valuable advise will be helpful. Thanks a lot.

1 Answers

1
cygri On

You are using the method Field.getDeclaredAnnotation(Class). This method was introduced in Java 8. It is not available in Java 7 and earlier. You need to upgrade your JDK.

Field is a subclass of AccessibleObject and inherits the method from that class. See the Javadoc: It says “Since: 1.8” which is the version for Java 8 in the internal numbering scheme.