It is a small general-purpose library includes:
- set of run-time annotations to mark code
- set of utility classes
- shaded com.google.code.findbugs:jsr305 annotation library
- maven plugin to log info about some annotations and check java class version
-
1.2.1 (14-dec-2024)
-
added annotations PureFunction and DisableSelfInvocation
-
added
checkfunctions intoTimeGuard -
fixed search for classes in META-INF for checker
-
refactoring
-
1.2.0 (10-dec-2024)
-
minimal JDK 11
-
minimal Maven 3.8.1
-
removed vulnerable dependencies
-
minor renaming of methods
-
use of Joda Time replaced by Java Time API
-
updated dependencies and improved new JDK support
-
refactoring and typo fixing
It contains number annotations to mark code, plus JSR-305 annotations provided by the shaded findbugs annotation library.
- ImplementationNote
- UiThread
- Critical
- Constraint
- Determined
- NonDetermined
- LazyInited
- Link
- MayContainNull
- MustNotContainNull
- NeedsRefactoring
- OneWayChange
- PureFunction
- ReturnsOriginal
- Risky
- ToDo
- Warning
- Weight
- ThrowsRuntimeException
- ThrowsRuntimeExceptions
- Experimental
- TimeComplexity
- MemoryComplexity
To use annotations just add dependency to the library
<dependency>
<groupId>com.igormaznitsa</groupId>
<artifactId>meta-annotations</artifactId>
<version>1.2.1</version>
</dependency>
It shades JSR-305 annotations from the FindBugs library so that they also will be available for usage automatically.
Since 1.1.0 utility classes extracted into separated module which is available in maven central Just add the lines below into build section.
<dependency>
<groupId>com.igormaznitsa</groupId>
<artifactId>meta-utils</artifactId>
<version>1.2.1</version>
</dependency>
It allows to defer some operations, like it works in Go but unfortunately the call to process all deferred operations must be placed into try...finally block to ensure the call.
It checks stack frames and all deferred operations will be processed by Deferrers.processDeferredActions() only for actual stack depth, it means that deferred operations added on higher stack levels will be ignored.
try {
// it processes runnable, the code will be executed
Deferrers.defer(new Runnable() {public void run() { System.out.println("Hello world");}});
final InputStream is = new FileInputStream("/home/test/nonexistfile.txt");
// it processes closeable, registered closeable object will be closed automatically
Deferrers.defer(is);
}
finally {
Deferrers.processDeferredActions();
}
final TimeGuard.TimeAlertListener listener = new TimeGuard.TimeAlertListener() {
@Override
public void onTimeAlert(long l, TimeGuard.TimeData td) {
System.out.println("Too long delay for " + td.getAlertMessage());
}
};
try {
TimeGuard.addGuard("Checkpoint1", 100L, listener);
Thread.sleep(200L);
}
finally {
TimeGuard.check();
}
I have also published some maven plugin which allows to check compiled classes for the annotations and print some information and check that methods marked by nullable and nonnull annotations. Also the plugin allows to fail build process if detected some annotations, it allows to avoid publishing of project with to-do or experimental stuff.
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>meta-checker</artifactId>
<version>1.2.1</version>
<configuration>
<restrictClassFormat>7</restrictClassFormat>
<failForAnnotations>
<param>risky</param>
</failForAnnotations>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>