Aspect AbstractNullPointerTrap
- java.lang.Object
-
- patterntesting.check.runtime.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.
- Since:
- 11.12.2007
-
Pointcut Summary public applicationCode()
Specify what the application code is that should be subject to the pattern test.public nullArgsAllowed()
Specify which code is allowed to havenull
parameters.public mayReturnNull()
Specify which methods may returnnull
.(package private) invalidNullParameter()
Addresses all methods (or constructors) with at least one argument which should not be given as null parameter.Advice Summary before(): invalidNullParameter..
If a (null) parameter is detected something is wrong with the application code.Advises: patterntesting.check.runtime.ZombieException.ZombieException, patterntesting.check.runtime.DeprecatedCodeException.DeprecatedCodeException afterReturning(java.lang.Object): nonVoidMethods..
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
assertEnabled
The Constant assertEnabled.
-
Constructor Summary
Constructors Constructor Description AbstractNullPointerTrap()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract org.apache.logging.log4j.Logger
getLog()
To get the aspect specific logger.
-
-
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..