Aspect AbstractNullPointerTrap

  • Direct Known Subclasses:
    NullPointerTrap

    public abstract aspect AbstractNullPointerTrap
    extends java.lang.Object
    In the AbstractNullTest aspect we log only if a null value is given to a method. The NullPointerTrap here is much stricter: it requires that
    • no null value is given
    • null as return value is forbidden
    • if one of this requirements are hurt an AssertionExecption is thrown.
    As in AbstractNullTest you can define exceptions from these strict rules by defining the abstract pointcuts applicationCode, nullArgsAllowed
  • and mayReturnNull. This aspect is intended more for finding bugs in the test phase whereas AbstractNullTest can be also used during production because it logs only the problematic calls with a null parameter.
Since:
11.12.2007
  •  

    Pointcut Detail

    applicationCode()

    Specify what the application code is that should be subject to the pattern test.
    Ex: pointcut applicationCode(): within(patterntesting.sample.*)


    nullArgsAllowed()

    Specify which code is allowed to have null parameters.
    Ex: execution(@NullArgsAllowed * *..*(*, ..)) || execution(@NullArgsAllowed *..new(*, ..))


    mayReturnNull()

    Specify which methods may return null. Some methods (like find methods or getters) may return a null value.
    Ex: execution(@MayReturnNull Object+ *..*(..))


    invalidNullParameter()

    Addresses all methods (or constructors) with at least one argument which should not be given as null parameter. For performance reason this is limited only to public methods (or constructors)


     

    Advice Detail

    before

    before(): invalidNullParameter..

    If a (null) parameter is detected something is wrong with the application code.

    Inner classes will be skipped because they are handled different by the compiler (for private static inner classes it adds an additional argument for the default constructor. But this additional argument is always null).

    Also some methods from the Object class (e.g. the equals method) are also skipped because these methods are prepared for null arguments.

     Advises:patterntesting.check.runtime.ZombieException.ZombieException, patterntesting.check.runtime.DeprecatedCodeException.DeprecatedCodeException


    afterReturning

    afterReturning(java.lang.Object): nonVoidMethods..

     Advises:patterntesting.check.runtime.DeprecatedAspect.getLog, patterntesting.check.runtime.DeprecatedAspect.getMarker, patterntesting.check.runtime.ZombieAspect.getLog, patterntesting.check.runtime.ZombieAspect.getMarker

    • Field Detail

      • assertEnabled

        protected static final boolean assertEnabled
        The Constant assertEnabled.
    • Constructor Detail

      • AbstractNullPointerTrap

        public AbstractNullPointerTrap()
    • Method Detail

      • getLog

        public abstract org.apache.logging.log4j.Logger getLog()
        To get the aspect specific logger.
        Returns:
        the logger