Skip to content

KetothXupack/jsr305-aspectj-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis status

jsr305-aspectj-validation

AspectJ-powered way to bring JSR-305 validations on run-time.

How to use

import javax.annotation.Nonnull;

public class Example {
    /* this object should not have null value */
    private Object o;

    public Example(@Nonnull final Object obj) {
        this.o = obj;
    }

    public void setObject(@Nonnull final Object obj) {
        this.o = obj;
    }

    @Nonnull
    public void setObject(@Nonnull final Object obj) {
        this.o = obj;
    }
}

Maven

To enable @Nonnull checks you need to modify your pom.xml

  1. Add build plugin:
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <configuration>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>org.no-hope</groupId>
                <artifactId>jsr305-aspectj-validation</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>
</plugin>
  1. Add validation dependency:
<dependency>
    <groupId>org.no-hope</groupId>
    <artifactId>jsr305-aspectj-validation</artifactId>
    <version>${validation.version}</version>
</dependency>

What is supported?

  • @Nonnull annotation:
  • Constructor parameters
  • Method parameters/return value

TODO/Limitations

  • @Nonnul support for fields
  • Support for other annotations
  • If @Nonnull annotation have value other than ALWAYS (default one) will cause validator to skip any non-null checking
  • No @ParametersAreNonnullByDefault/@ParametersAreNullableByDefault supported yet (waiting for AspectJ support)
  • All method parameters/return value considered nullable unless parameter/method have @Nonnull annotation

About

AspectJ-powered way to bring jsr305 validations on run-time

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages