Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class.getAnnotation and getAnnotations doesn't work properly

Class SecureDispatchService from gwt like this:

@RemoteServiceRelativePath("dispatch")
public interface SecureDispatchService extends RemoteService {
    Result execute( String sessionId, Action<?> action ) throws DispatchException;
}

RemoteServiceRelativePath:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RemoteServiceRelativePath {
  /**
   * The relative path for the {@link RemoteService} implementation.
   * 
   * @return relative path for the {@link RemoteService} implementation
   */
  String value();
}

Test code is very simple:

package com.name.sbts.wbts.sm;

import net.customware.gwt.dispatch.client.secure.SecureDispatchService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

public class TestClass {

    public static void main(String[] args) {

        Class c = SecureDispatchService.class;
        System.out.println(c.getAnnotation(RemoteServiceRelativePath.class));
        System.out.println(c.getAnnotations().length);
    }
}

But the result is not wanted:

null
0

I was running this code in eclipse, with JRE1.7

SecureDispatchService is in this jar from google:

gwt-dispatch-1.2.0.jar

I used mvn eclipse:eclipse to generate the project. This jar file is as a referenced libraries of eclipse project, and its real path is in my .m2/repostory.

like image 764
Jerry Z. Avatar asked Oct 31 '22 07:10

Jerry Z.


1 Answers

This is happening because gwt-dispatch project is compiled using old gwt-user dependency (gwt version 2.0.4). In this version of gwt the RemoteServiceRelativePath annotation doesn't have @Retention(RetentionPolicy.RUNTIME) on it, so the RemoteServiceRelativePath annotation is not available at the runtime.

like image 143
Aleksandr M Avatar answered Nov 09 '22 06:11

Aleksandr M