WALA icon indicating copy to clipboard operation
WALA copied to clipboard

why the annotation is null

Open liberatorqjw opened this issue 5 years ago • 7 comments

jdk: 1.8

my example is a spring demo. I write as follows: but i get the getAnnotations() is always null. Spring demo

@RestController
@RequestMapping(value="/test")
public class TestCtrl {
	
	@Autowired
	private RedisService redisService;
	
	@Autowired  
    private UserInfoMapper userInfoMapper;  

    @RequestMapping(value="/index")
    public String index(){
        return "hello world";
    }
    
    /**
     * 向redis存储值
     * @param key
     * @param value
     * @return
     * @throws Exception
     */
    @RequestMapping("/set")  
    public String set(String key, String value) throws Exception{

        redisService.set(key, value);
        return "success";  
    }  
    
    /**
     * 获取redis中的值
     * @param key
     * @return
     */
    @RequestMapping("/get")  
    public String get(String key){  
        try {
			return redisService.get(key);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";  
    }  
    

wala demo

        for (IClass klass : cha) {
            if (klass.getClassLoader().getReference().equals(clr)) {
                //TODO: REFACTOR OOP/ Maybe with a list
                if (klass.getName().toString().startsWith("Lorg/springframework"))
                    continue;
                if (klass.getAnnotations() == null)
                    continue;

                for (Annotation annotation : klass.getAnnotations()) {
                    if (isSpringComponent(annotation,cha)) {
                        //check for class methods as entry points
                        //TODO: Grab only methods mapped
                        for (IMethod iMethod : klass.getAllMethods()) {
                            if (isSpringMapping(iMethod)) {
                                result.add(new SpringEntrypoint(iMethod,cha));
                            }
                        }
                    }

                }
//                IMethod m = klass.getMethod(mainRef.getSelector());
//                if (m != null) {
//                    result.add(new DefaultEntrypoint(m, cha));
//                }
            }
        }

Thanks

liberatorqjw avatar Oct 24 '19 07:10 liberatorqjw

Are you analyzing source code or bytecode?

On Thu, Oct 24, 2019 at 00:02 Jiawei Qin [email protected] wrote:

jdk: 1.8

my example is a spring demo. I write as follows: but i get the getAnnotations() is always null. Spring demo

@RestController

@RequestMapping(value="/test")

public class TestCtrl {

@Autowired

private RedisService redisService;

@Autowired

private UserInfoMapper userInfoMapper;



@RequestMapping(value="/index")

public String index(){

    return "hello world";

}



/**

 * 向redis存储值

 * @param key

 * @param value

 * @return

 * @throws Exception

 */

@RequestMapping("/set")

public String set(String key, String value) throws Exception{



    redisService.set(key, value);

    return "success";

}



/**

 * 获取redis中的值

 * @param key

 * @return

 */

@RequestMapping("/get")

public String get(String key){

    try {

  	return redisService.get(key);

  } catch (Exception e) {

  	e.printStackTrace();

  }

  return "";

}

wala demo

    for (IClass klass : cha) {

        if (klass.getClassLoader().getReference().equals(clr)) {

            //TODO: REFACTOR OOP/ Maybe with a list

            if (klass.getName().toString().startsWith("Lorg/springframework"))

                continue;

            if (klass.getAnnotations() == null)

                continue;



            for (Annotation annotation : klass.getAnnotations()) {

                if (isSpringComponent(annotation,cha)) {

                    //check for class methods as entry points

                    //TODO: Grab only methods mapped

                    for (IMethod iMethod : klass.getAllMethods()) {

                        if (isSpringMapping(iMethod)) {

                            result.add(new SpringEntrypoint(iMethod,cha));

                        }

                    }

                }



            }

// IMethod m = klass.getMethod(mainRef.getSelector());

// if (m != null) {

// result.add(new DefaultEntrypoint(m, cha));

// }

        }

    }

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wala/WALA/issues/574?email_source=notifications&email_token=AABPEUM22ERBG3CIJCPWKVDQQFCBLA5CNFSM4JEPWON2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HUAVHUQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABPEULBF72ZLFKXXKFYOATQQFCBLANCNFSM4JEPWONQ .

msridhar avatar Oct 24 '19 13:10 msridhar

I analyzed the source code as follows:

 scope.addToScope(ClassLoaderReference.Application, new SourceDirectoryTreeModule(new File(sourceDir)));

        // build the class hierarchy
        IClassHierarchy cha = ClassHierarchyFactory.make(scope, new com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory(scope.getExclusions()));
//      

liberatorqjw avatar Oct 25 '19 05:10 liberatorqjw

Ok, yes, this is using the source front end. @juliandolby are annotations supported in the source front end?

msridhar avatar Oct 25 '19 15:10 msridhar

I can not get the @requestmapping and any more class annotions

liberatorqjw avatar Oct 25 '19 16:10 liberatorqjw

Hi @juliandolby, @msridhar : Does the java source code support recognition class's annotations? or Or which mode supports this kind of operation?

Thanks

liberatorqjw avatar Oct 30 '19 07:10 liberatorqjw

Annotations are definitely supported in the bytecode frontend. @juliandolby would know about source front end.

msridhar avatar Nov 01 '19 17:11 msridhar

Ok, Thanks for your help I am looking forward to hear from @juliandolby

liberatorqjw avatar Nov 02 '19 12:11 liberatorqjw