GithubHelp home page GithubHelp logo

osundblad / intellij-annotations-instrumenter-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vladrassokhin/intellij-annotations-instrumenter-maven-plugin

38.0 38.0 10.0 486 KB

IntelliJ IDEA annotations instrumenter maven plugin

License: Other

Java 100.00%

intellij-annotations-instrumenter-maven-plugin's People

Contributors

atorstling avatar jkaving avatar johgr814 avatar oloflarsson avatar osundblad avatar vladrassokhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

intellij-annotations-instrumenter-maven-plugin's Issues

Gradle support

Hi!
I see you wrote

Isolated Maven plugin dependencies to allow usage without Maven

But what would that mean? The "processor(s)" extends Maven classes, thus they can be used via Maven only. Do you mean I could take your work and without much hassle convert it to support other build tools?

Thanks!

Void reference return type requires @Nullable in implicit mode

When using implicit mode the code below requires adding a @Nullable annotation to the call() method.
Since the Void reference type is only used to signify that we are not interested in the return value (and the only allowed return value is null) we probably shouldn't throw an IllegalStateException here.

Callable<Void> callable = new Callable<Void>() {
    @Override
    public Void call() {
        ... 
        return null;
    }
};

Implicit instrumentation does not work well for lambdas

Found a, rather serious, issue with the synthetic method detection. This results in that more methods than intended are instrumented when using the implicit instrumentation (both global and class).

The only case where I found issues with this is when using lambdas and threading, but it might affect more so be careful with implicit instrumentation until I have patched it tonight (version 0.62)

Java 11 Support

Instrumentation fails for a Java 11 build:

Failed to execute goal se.eris:notnull-instrumenter-maven-plugin:0.6.8:instrument (default) on project ....: Execution default of goal se.eris:notnull-instrumenter-maven-plugin:0.6.8:instrument failed: NotNull instrumentation failed for ....: Unsupported class file major version 55 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal se.eris:notnull-instrumenter-maven-plugin:0.6.8:instrument (default) on project ....: Execution default of goal se.eris:notnull-instrumenter-maven-plugin:0.6.8:instrument failed: NotNull instrumentation failed for ....
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal se.eris:notnull-instrumenter-maven-plugin:0.6.8:instrument failed: NotNull instrumentation failed for ....
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 20 more
Caused by: se.eris.notnull.InstrumentExecutionException: NotNull instrumentation failed for ....
        at com.intellij.NotNullInstrumenter.instrumentFile(NotNullInstrumenter.java:74)
        at com.intellij.NotNullInstrumenter.instrumentDirectoryRecursive(NotNullInstrumenter.java:64)
        at com.intellij.NotNullInstrumenter.addNotNullAnnotations(NotNullInstrumenter.java:57)
        at com.intellij.AbstractNotNullInstrumenterTask.instrument(AbstractNotNullInstrumenterTask.java:77)
        at com.intellij.ClassesNotNullInstrumenter.execute(ClassesNotNullInstrumenter.java:45)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 21 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 55
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:166)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:148)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:136)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:237)
        at com.intellij.NotNullInstrumenter.instrumentClass(NotNullInstrumenter.java:80)
        at com.intellij.NotNullInstrumenter.instrumentFile(NotNullInstrumenter.java:72)
        ... 26 more

I tried updating the asm dependency to 6.2.1 or 7.0-beta, which supports Java 11, but this fails with a 'This feature requires ASM7' message (don't know how to fix this).

Enum parameter bug

Parameters in Enums are offset thus instrumenter hit wrong parameter.

Unable to instrument javax.annotation

I have a large project that has a mix of org.jetbrains.annotations and javax.annotation for notNull and nullable (don't ask).

I can't seem to get the javax.annotation annotations to instrument just the org.jetbrains.annotations.

with just the org.jetbrains.annotations I get the files that have it instrumented...

[INFO] --- notnull-instrumenter-maven-plugin:0.6.6:instrument (default) @ myproject ---
[info] Using the following NotNull annotations:
[info]   org.jetbrains.annotations.NotNull
[info] Using the following Nullable annotations:
[info]   org.jetbrains.annotations.Nullable
[info] Instrumented 2 files with NotNull assertions

with just the javax.annotation get none of the files instrumented... (there are 50+)...

[INFO] --- notnull-instrumenter-maven-plugin:0.6.6:instrument (default) @ pegasus ---
[info] Using the following NotNull annotations:
[info]   javax.annotation.NotNull
[info] Using the following Nullable annotations:
[info]   javax.annotation.Nullable
[info] Instrumented 0 files with NotNull assertions

I've set up my pom.xml file with the default but added the configuration section as such:

	<!--https://github.com/osundblad/intellij-annotations-instrumenter-maven-plugin-->
	<plugin>
		<groupId>se.eris</groupId>
		<artifactId>notnull-instrumenter-maven-plugin</artifactId>
		<version>0.6.6</version>
		...
		<configuration>
			<notNull>
				<!--<param>org.jetbrains.annotations.NotNull</param>-->
				<param>javax.annotation.NotNull</param>
			</notNull>
			<nullable>
				<!--<param>org.jetbrains.annotations.Nullable</param>-->
				<param>javax.annotation.Nullable</param>
			</nullable>
		</configuration>
	</plugin>

I've done <implicit>true</implicit> but that covers everything (200+ files) and is unrealistic for me at this point.

I'm I doing something wrong or is this scenario unsupported at this point?

Implicit NotNull instrumentation should not apply to type parameters

Implicit not-null instrumentation should not be applied to not annotated parameters/return values whose type is a (not annotated) type parameter.

The reason is that the type arguments themselves can be annotated (with Java 8 type use annotations) by the caller himself to his preference (e.g. List<@Nullable String> vs. List<@NotNull String>) and intended nullability (from the caller point of view) may conflict with statically instrumented bytecode (and its implied not-null contract), causing false-positive IllegalArgumentExceptions and/or NullPointerExceptions being thrown.

E.g. this code:

public class Holder<T> {
    private final T t;
    public Holder(T t) { this.t = t; }
    public T get() { return t; }
    public static void main(String[] args) {
        @Nullable Integer i = new Holder<@Nullable Integer>(null).get();
    }
}

will throw an IllegalArgumentException when main method is invoked (if built with <implicit>true</implicit> configuration of the plugin).

Unpack attached intellij-annotations-instrumenter-maven-plugin-15.zip and run mvn clean process-classes && java -cp target/classes com.example.Holder from its root directory to reproduce.

Enhancement under JDK17 fails with PermittedSubclasses requires ASM9

Caused by: java.lang.RuntimeException: java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9
    at com.intellij.compiler.instrumentation.InstrumenterClassWriter.getCommonSuperClass (InstrumenterClassWriter.java:53)
    at org.objectweb.asm.SymbolTable.addMergedType (SymbolTable.java:1202)
    at org.objectweb.asm.Frame.merge (Frame.java:1299)
    at org.objectweb.asm.Frame.merge (Frame.java:1207)
    at org.objectweb.asm.MethodWriter.computeAllFrames (MethodWriter.java:1610)
    at org.objectweb.asm.MethodWriter.visitMaxs (MethodWriter.java:1546)
    at org.objectweb.asm.MethodVisitor.visitMaxs (MethodVisitor.java:773)
    at com.intellij.compiler.notNullVerification.ThrowOnNullMethodVisitor.visitMaxs (ThrowOnNullMethodVisitor.java:146)
    at org.objectweb.asm.ClassReader.readCode (ClassReader.java:2665)
    at org.objectweb.asm.ClassReader.readMethod (ClassReader.java:1514)
    at org.objectweb.asm.ClassReader.accept (ClassReader.java:744)
    at org.objectweb.asm.ClassReader.accept (ClassReader.java:424)
    at com.intellij.NotNullInstrumenter.instrumentClass (NotNullInstrumenter.java:91)
    at com.intellij.NotNullInstrumenter.instrumentFile (NotNullInstrumenter.java:75)
    at com.intellij.NotNullInstrumenter.instrumentDirectoryRecursive (NotNullInstrumenter.java:67)
    at com.intellij.NotNullInstrumenter.instrument (NotNullInstrumenter.java:61)
    at com.intellij.NotNullInstrumenter.instrument (NotNullInstrumenter.java:56)
    at com.intellij.AbstractNotNullInstrumenterTask.instrument (AbstractNotNullInstrumenterTask.java:77)
    at com.intellij.ClassesNotNullInstrumenter.execute (ClassesNotNullInstrumenter.java:45)

Turn off instrumentation

Turn off instrumentation with an environment variable or a maven property. This is useful when you want to have the instrumentation in the main build configuration, but not in a specific maven profile, for example, when running static code analysis (eg Sonar).

Stop double check on Kotlin files

Hello,
I have set up the plugin to add the null-checks in my modules. The modules are generated based on mixed java and kotlin files.
The pitty side effect is, that even my original kotlin files are processed by Your plugin and have now a double-check for null.


if (param == null) {
throw new IllegalArgumentException("NotNull annotated argument 0 of must not be null");
}
Intrinsics.checkNotNullParameter(param, (String)"param");

Is there any chance to avoid the "double-check" and to skip all files originally based on Kotlin?

Thanks a lot,

Matthias

Allow @ImplicitNotNull in package-info

  • Add support for @ImplicitNotNull in package info
  • Add value param true/false to specify if implicit instrumentation should be done on package or not (default true)

Instrumentation causing coverage checks to fail

I pretty much have the minimal setup for instrumentation. Not all the classes have nullable or nonnull annotations.

<!--https://github.com/osundblad/intellij-annotations-instrumenter-maven-plugin-->
<plugin>
	<groupId>se.eris</groupId>
	<artifactId>notnull-instrumenter-maven-plugin</artifactId>
	<version>0.6.6</version>
	<executions>
		<execution>
			<goals>
				<goal>instrument</goal>
				<goal>tests-instrument</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<notNull>
			<param>javax.annotation.Nonnull</param>
		</notNull>
		<nullable>
			<param>javax.annotation.Nullable</param>
		</nullable>
	</configuration>
</plugin>		

I have default-jacoco-check maven phase that has the following rule set:

<rule implementation="org.jacoco.maven.RuleConfiguration">
	<element>BUNDLE</element>
	<limits>
		<limit implementation="org.jacoco.report.check.Limit">
			<counter>INSTRUCTION</counter>
			<value>COVEREDRATIO</value>
			<minimum>0.87</minimum>
		</limit>

The coverage before instrumentation was 89%... after it reports 79% (and fails building). Looking at the coverage report shows that all the classes that have nonnull/nullable are the ones that are falling in coverage percentage.

I'm I missing something here or is this not going to be compatible with using default-jacoco-check?

Java10 support

Tried to run this with Java 10 and got

java.lang.IllegalArgumentException
	at org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at com.intellij.NotNullInstrumenter.instrumentClass(NotNullInstrumenter.java:80)
	at com.intellij.NotNullInstrumenter.instrumentFile(NotNullInstrumenter.java:72)

I suppose it might be caused by an unsupported class file version. But I'm just guessing.

exclusion not working as expected

Hello.
I faced the issue that is related to exclusion
Verison of plugin: 0.6.9-RC2

We want to exclude generated classes from checks
(packages modified)
java.lang.IllegalArgumentException: Implicit NotNull argument 0 (parameter 'value') of com/a/b/avro/c/d/Opportunity$Builder.setJobId must not be null
at com.a.b.avro.c.d.Opportunity$Builder.setJobId(Opportunity.java) ~[classes/:na]

Our excusion is defined this way:

<excludes>
   <classes>**.xmlns.**</classes>
   <classes>**.avro.**</classes>
   <classes>**.events.**</classes>
   <classes>**.records.**</classes>
   <classes>**.openapitools.**</classes>
</excludes>

Is there an issue with exclude related to inner classes or i misunderstood the wildcard pattern ?

A required class was missing: org/jetbrains/annotations/NotNull

I'm trying to use 0.6.9-RC2 on Java 11, but am getting:

[ERROR] Failed to execute goal se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2:instrument (default) on project build-tools:
Execution default of goal se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2:instrument failed:
A required class was missing while executing se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2:instrument: org/jetbrains/annotations/NotNull

It's a little puzzling, because

<dependency>
    <groupId>org.jetbrains</groupId>
    <artifactId>annotations</artifactId>
    <version>15.0</version>
</dependency>

is in the dependencies...

This used to work fine with v 0.6.8 and Java 8.

Full error message:


[ERROR] Failed to execute goal se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2:instrument (default) on project build-tools: Execution default of goal se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2:instrument failed: A required class was missing while executing se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2:instrument: org/jetbrains/annotations/NotNull
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>se.eris:notnull-instrumenter-maven-plugin:0.6.9-RC2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/hendrik/.m2/repository/se/eris/notnull-instrumenter-maven-plugin/0.6.9-RC2/notnull-instrumenter-maven-plugin-0.6.9-RC2.jar
[ERROR] urls[1] = file:/Users/hendrik/.m2/repository/org/apache/maven/maven-builder-support/3.3.9/maven-builder-support-3.3.9.jar
[ERROR] urls[2] = file:/Users/hendrik/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar
[ERROR] urls[3] = file:/Users/hendrik/.m2/repository/org/eclipse/aether/aether-util/1.0.2.v20150114/aether-util-1.0.2.v20150114.jar
[ERROR] urls[4] = file:/Users/hendrik/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar
[ERROR] urls[5] = file:/Users/hendrik/.m2/repository/org/eclipse/sisu/org.eclipse.sisu.inject/0.3.2/org.eclipse.sisu.inject-0.3.2.jar
[ERROR] urls[6] = file:/Users/hendrik/.m2/repository/com/google/inject/guice/4.0/guice-4.0-no_aop.jar
[ERROR] urls[7] = file:/Users/hendrik/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[ERROR] urls[8] = file:/Users/hendrik/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.21/plexus-interpolation-1.21.jar
[ERROR] urls[9] = file:/Users/hendrik/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[10] = file:/Users/hendrik/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.6/plexus-component-annotations-1.6.jar
[ERROR] urls[11] = file:/Users/hendrik/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[12] = file:/Users/hendrik/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[13] = file:/Users/hendrik/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar
[ERROR] urls[14] = file:/Users/hendrik/.m2/repository/org/ow2/asm/asm/7.0/asm-7.0.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>com.tagtraum:build-tools:5.2.0-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

Inner class constructor parameter's annotation is broken

Create an inner class constructor with 1st parameter annotated as @Nullable, and 2nd parameter annotated as @NotNull and pass null in first argument there. You should end up having something like:

import org.jetbrains.annotations.*;

public class SomeClass {
    public SomeClass() {
        new InnerClass( null, new Object());
    }

    public class InnerClass {
        public InnerClass(
            @Nullable Object aNullableParam,
            @NotNull Object aNotNullParam
        ) {
            System.out.println("InnerClass constructor");
        }
    }
}

Now running this in a small test using jUnit4/5 and maven will produce the following error:

Running SomeTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.057 sec <<< FAILURE!
createSomeClass(SomeTest)  Time elapsed: 0.005 sec  <<< ERROR!
java.lang.IllegalArgumentException: NotNull annotated argument 1 of SomeClass$InnerClass.<init> must not be null
	at SomeClass$InnerClass.<init>(SomeClass.java)
	at SomeClass.<init>(SomeClass.java:5)
	at SomeTest.createSomeClass(SomeTest.java:6)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

You can also check my test project attached here
playground.zip

Possible vanilla-JSpecify option?

This issue is really about "let's discuss the relationship between this project and JSpecify, whatever you might want that to be", and there's no urgency to it.

In JSpecify the makers of the various nullness annotations (including JetBrains) are agreeing for the first time on precise semantics for what they should mean, and of course a single well-documented jar to eventually deprecate the rest in favor of.

I assume your users can just add our package name to your config file and get something useful out of it. But for a project that has fully adopted JSpecify annotations and semantics, they might see value in a "use vanilla JSpecify" option of some kind. An example I thought of first is that your tool would then obey the presence of @NullMarked and @NullUnmarked, and disallow the implicit-annotations option.

Whether you would expect to ever do this or not, it would be very (very) helpful to know whether you notice anything about the JSpecify semantics that would cause a conflict/obstacle to the kinds of things you might want to do. We are mostly working with authors of compile-time analyzers, but would love to have someone involved from the runtime instrumentation perspective.

Of course, if you see nothing to do then just close this.

Include/exclude on packages when using implicit instrumentation

If you have generated sources that are compiled into the project classpath they will be instrumented. This is might be a bad idea since everything will be NotNull even if the generated code does not support that (eg cxf).

Setting exclude/include in config solves this.

Default execution configuration

This should be default:

<executions>
      <execution>
           <id>instrument</id>
           <goals>
                <!--suppress MavenModelInspection -->
                <goal>instrument</goal>
                <!--suppress MavenModelInspection -->
                <goal>tests-instrument</goal>
           </goals>
      </execution>
</executions>

@Implicit at class level

The implicit setting was great! However it is hard to migrate to this setting in larger projects. It would be nice to have an class level implicit setting. Then it would be possible to migrate class by class.

Java 13 support

Since I upgraded to asm 9.0 Java 13 support is hopefully quite easy.

Anonymous class constructor parameters should inherit nullability from parent

There's no way (i know of) to annotate anonymous class constructor parameters.

Having these inherit @Nullable/@NotNull annotations from implicitly invoked parent constructor would extend safety checks to anonymous class constructors (and prevent false positives for parent parameters annotated as @Nullable in case <implicit>true</implicit> configuration is used).

Allow a configurable Exception to be thrown upon detecting that an invariant does not hold

If, for example, a method with a @NotNull parameter is invoked with null (despite the contract), I would expect that method to throw NullPointerException rather than an IllegalArgumentException. This would better mimic the customary use of Objects::requireNonNull null invariant assertion and would allow the removal of all these calls with no impact on production and test code.

Thus, it would be advantageous to be able to set the type of exception thrown. Preferably as a Maven configuration property. If a general exception supplier setting is not easy to do, then at least a <useNullPointerException>true</useNullPointerException> could be considered.

See ThrowOnNullMethodVisitor.IAE_CLASS_NAME

Open up for co-maintainers

I see several comments mentioning you do not have time to keep the project updated. We were thinking of using this in our organization, but we are a bit wary of starting to use software where the maintainer explicitly acknowledges he does not have time to allocate to maintaining it (ref #29 (comment)). By this, I do not mean to imply you are obligated in any way to spend your free time maintaining it, just that it's a bit of a showstopper ๐Ÿ˜„

So, as someone with a hand on maintaining a lot of open source projects in my spare time (like Sinon), I thought I would come with some constructive suggestions instead! Why not add a "Maintainers wanted" issue and link it from the top of your README.md, asking for volunteers to help you out in maintaining this? We have had good results doing this in Sinon. Having 2-3 extra peeps helping out with PR reviews and pushing updates to Maven central does help, while at the same time you can still keep ownership. Labelling issues as "up for grab" and registering with sites such as https://up-for-grabs.net, https://goodfirstissue.dev, https://github.com/cutenode/good-first-issue and https://www.firsttimersonly.com also improves resolution speed, but demands time to close the PRs.

Redundant instrumentation

When building with maven and running the two commands in succession instrumentation will happen twice.

mvn test
mvn verify

For the first command the instrumentation goal is run after compilation. For the second command the instrumentation is run again although the compilation step was skipped with the message

Nothing to compile - all classes are up to date

This is not a semantic bug since a null check will either fail on the first or pass two times but is probably unintended since it just bloats the binary.

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T20:49:05+01:00)
notnull-instrumenter-maven-plugin 0.6.8
Java Oracle JDK 11.0.1
Windows 10

Plugin in 1.1.0-SNAPSHOT version not works

Failed to execute goal se.eris:notnull-instrumenter-maven-plugin:1.1.0-SNAPSHOT:instrument (default) on project task-service-core: Execution default of goal se.eris:notnull-instrumenter-maven-plugin:1.1.0-SNAPSHOT:instrument failed: A required class was missing while executing se.eris:notnull-instrumenter-maven-plugin:1.1.0-SNAPSHOT:instrument: org/jetbrains/annotations/NotNull

adding jetbrains annotations dependency in plugin section, fix the problem:

<plugin>
                <groupId>se.eris</groupId>
                <artifactId>notnull-instrumenter-maven-plugin</artifactId>
                <version>1.1.0-SNAPSHOT</version>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains</groupId>
                        <artifactId>annotations</artifactId>
                        <version>20.1.0</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>instrument</goal>
                            <goal>tests-instrument</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

maven version:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Java version: 1.8.0_272, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: pl_PL, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-52-generic", arch: "amd64", family: "unix"

Java verson:

openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-8u272-b10-0ubuntu1~18.04-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode

sample project: https://github.com/alapierre/task-service

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.