Hacker News new | ask | show | jobs
by darthbanane 1098 days ago
Some of the aspect oriented stuff like cacheable will add a proxy to the annotated bean which can break reasoning about the code.

If you inject the bean and call the method you will get caching (because you are using the proxy). If you call the method from within the bean itself however you're not using the proxy and you won't get caching.

It's stuff like this on steroids when you start mixing annotations that makes it really difficult to reason about the code.

2 comments

I know this case. Indeed it adds some complexity in debugging and it does require that the user of such annotation understands how it works and what are the side effects. However this is probably the only case that causes so much trouble and it would deserve a dedicated compiler or IDE warning* for inexperienced engineers. There are many ways to shoot in the leg by using some tool or API incorrectly - it doesn’t mean the tool is bad.

*I would do it by introducing a new annotation:

   @ProxyImplementation
   public @interface Cacheable {}
Compiler can trigger a warning when a method invokes another method of the same class which is annotated with annotation marked as implemented by proxy.

Maybe Sonar or similar tool already does this kind of analysis.

Hehe, that specific case is probably something that most people run into at least once. I've seen several cases of it in production too, where someone refactored something years in the past and accidentally disabled the cache without anyone noticing.