1

I have a Java Maven project which is developed by multiple people.

As I really like doing JUnit Tests and the like, the concept of OVal intrigues me because I can write code like:

@NotNull
@NotEmpty
@Length(max=32)
private String name

However the disadvantage is that:

  • everyone now has to install the AspectJ plugin to his Eclipse
  • at least for me that gives me an error at each startup (which I can click away but it is still annoying)
  • I guess AspectJ slows everything down

So is it worth it and is there an alternative where I don't need AspectJ?

P.S.: This is the error I get in Eclipse: screenshot http://img651.imageshack.us/img651/1089/aspectjerror.png

And this is the head of the method getCommonProperties() that it seems to have problems with:

public static LinkedHashMap<String,Integer> getCommonProperties
(
    @NotEmpty @NotNull String endpoint,
    @NotEmpty @NotNull String where,
    @Range(min=0, max=1) Double threshold,
    @Min(1) Integer maxResultSize,
    @Min(1) Integer sampleSize
)
sversch
  • 856
  • 8
  • 22
Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118

2 Answers2

3

OVal does not require the usage of AspectJ per se. Only if you want to use it for programming-by-contract, e.g. automatic method parameter validation. If you do not want to use AspectJ you can use Spring AOP as an alternative to enable method parameter validation of Spring managed services, see http://oval.sourceforge.net/userguide.html#spring-aop

Georg
  • 46
  • 1
  • Well in fact in use OVal **only** for automatic method parameter validation so unfortunately I cannot skip AspectJ there. Regarding Spring AOP: If I don't use Spring is it worth it to include Spring AOP just for validation or does that take much time and resources to integrate into a normal Java application? – Konrad Höffner Oct 13 '11 at 16:20
  • 1
    Spring AOP uses dynamic proxy instances, this has some limitiations, e.g. it works only for public methods and you need to retrieve your objects via Spring meaning you cannot use the "new" keyword to instantiate objects. However I personally use Spring in all of my projects (client, sever, cmd line) and find it extremely useful. – Georg Oct 15 '11 at 22:24
  • Btw. regarding the NPE you get, did you try the workaround they describe here? https://bugs.eclipse.org/bugs/show_bug.cgi?id=353457 – Georg Oct 15 '11 at 22:25
2

I do not know the OVal framework, but I do know that AspectJ and the Eclipse tooling is mature. Compile time would be slightly longer due to the weaving process, but probably not significantly longer.

My suggestion is that if you find that the framework helps you, then it is worth using.

If you can tell me what the error on startup is, then perhaps we can figure out a way so that you don't get it any more.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • Thank you very much for the advice! Typically, I cannot get the error right now but I will post it the next time I get it :-) – Konrad Höffner Sep 29 '11 at 12:11
  • Ok I now recorded the problem. Do you know how I can fix it? – Konrad Höffner Oct 13 '11 at 16:21
  • 1
    This is a compiler exception thrown by the compiler. Looks like there is something about the method declaration that AspectJ is not able to handle. The best thing to do is to raise a bug report for this. Problems like this can often be fixed quickly. – Andrew Eisenberg Oct 13 '11 at 17:22