So I have the following code in one of my classes:
public void setName(@NotNull String name) {
this.name = name;
}
In some situations when I use them, I get errors like this (I do not want to discuss right now that the annotation is wrong when I am complaining about it throwing errors):
Caused by: java.lang.IllegalArgumentException: Argument 0 for @NotNull
parameter of org/rhq/core/domain/resource/Resource.setName must not
be null
at org.rhq.core.domain.resource.Resource.setName(Resource.java)
The @NotNull
Annotation is coming from the Jetbrains org.jetbrains.annotations
package.
Decompiling Resource.class
with jad Resource.class
shows this:
public void setName(String name)
{
if(name == null)
{
throw new IllegalArgumentException("Argument 0 for @NotNull parameter of org/rhq/core/domain/resource/Resource.setName must not be null");
} else
{
this.name = name;
return;
}
}
So someone is inserting this check for if(name==null)
on compile time. As we are building with maven and other team members do not see this, it looks like a local issue. But then, other team members have a very similar environment than I do.
[UPDATE]
I was suspecting IntelliJ already, as my colleague Ian was talking about the @NotNull compiler setting, but I turned that off and on and it had no effect.
After the comment by Scott Vachalek I went over this again -- especially as we are not using the IntelliJ compiler in our maven runs. I enabled the option, and compiled on command line. Nothing happened.
And then today I was running some unit tests from within IntelliJ and saw the "Looking for classes to compile ..." message in IntelliJ UI and then also messages about compiling. Then ran jad again and saw those checks again.
So it turns out that IntelliJ is compiling my classes with those @NotNull annotations again. And as this is in a maven build, it is putting the resulting classes in the places where a command line compile would also put them. My next command line build will then see that the class files are newer than the sources and not recompile them, but just include them in the resulting artifact.