开发者

Aspectj overwrite an argument of a method

I'm developing an aspect that checks arguments of setter methods and overwrites empty strings with null value. This is my state so far:

@Before("execution(* de.foo.entity.*.set*(..)) && args(java.lang.String)")
public void check(final JoinPoint jp) {
    LOGGER.debug(jp.getSignature().toLongString());
    Object[] args = jp.getArgs();
    for (int i = 0; i < args.length; i++) {
        if (args[i] instanceof String && ((String) args[i]).isEmpty()) {
            args[i] = null;
        }
    }
}

Unfortunately the overw开发者_JS百科rite statement args[i] = null; does now work! Do anyone know how should I overwrite it?

Cheers,

Kevin


I believe you have to implement an around advice, instead of a before advice.

Because you can use proceed with your new arguments:

proceed(newArgs);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜