osundblad / intellij-annotations-instrumenter-maven-plugin

IntelliJ IDEA annotations instrumenter maven plugin
Other
38 stars 11 forks source link

Inner class constructor parameter's annotation is broken #28

Open vkhozov opened 6 years ago

vkhozov commented 6 years ago

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

osundblad commented 5 years ago

Will look into this during X-mas.

osundblad commented 5 years ago

Sorry for not acting on this earlier (but this is a hobby project, even though I use it for production in work projects).

I think I have fixed the problem now. It seems like this was not supported even in the original version (tried to check the history) or I just messed up a refactoring somewhere before I managed to add tests. There are tests for this now.

osundblad commented 5 years ago

If you still use this project there is a 0.6.9-RC1 release on maven central now. I hopefully fixes that rather serious issue (have a unit test based on you code).

PS Therelease might not be visible on the web but I just verified that it is there.

osundblad commented 5 years ago

The RC1 release still had some bugs I think the 0.6.9-RC2 release should work though.

PeerHeijnen commented 4 years ago

Would be great if you get a release done. For me 0.6.7 works, but 0.6.8 still fails due to this issue.

osundblad commented 4 years ago

Hi, again late reply (I need help maintaining this). Does it work for 0.6.9-RC2 or 1.0.0 (released Sunday)?

I do have a test that verifies it in 0.6.9-RC2 but want to hear from you. (Sorry for closing issue)