PudiPudi
PudiPudi

Reputation: 38

Missorted modifiers on annotations since moving to spring boot 2

I migrated my project from Spring boot 1.5 to Spring boot 2. After doing so I have an Missorted modifiers @NotNull private on every field implementing the @NotNull annotation (from javax.validation.constraints.*. This warning disappears when switching branch back to 1.5

I tried disabling all plugin's on intelij and removing the custom configuration i had for Code-style and Inspection. Only valid information found when searching on warning of this type of error is stating that Intelij is taking the "java language specifications" but when looking into those it seems like it should still be annotations followed by modifiers and not the other way around. (https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.3.1)

// This does not give a warning
private @NotNull String myString1;

// This does give a warning, wanting me to reformat to the one above
@NotNull
private String myString2;

I want to keep the formatting as in the 2nd example, it being more readable than the one above. Certainly when using multiple fields.

Upvotes: 0

Views: 329

Answers (2)

PudiPudi
PudiPudi

Reputation: 38

As of Java 8, the TYPE_USE Annotation.Element_type has been introduced, this changes how the annotation is used (and how it behaves). It is because of this that it is now formatted differently short description can be found here: https://dzone.com/articles/java-8-type-annotations. Upgrading to Spring boot 2 I also updated

<dependency>
   <groupId>javax.validation</groupId>
   <artifactId>validation-api</artifactId>
   <version>1.1.0.Final</version>
</dependency>

to

<dependency>
   <groupId>javax.validation</groupId>
   <artifactId>validation-api</artifactId>
   <version>2.x.x</version>
</dependency>

Apparently, this was already changed when using the spring boot dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

long story short: we will have to get used to this for annotation using the TYPE_USE and TYPE_PARAMETER ElementTypes

I just had to spend some more time searching, asked it here out of frustration...

Upvotes: 1

yole
yole

Reputation: 97178

"Missorted modifiers" is an IntelliJ IDEA inspection that is disabled by default. If you enable it, it requires annotations to be placed before modifiers by default, but it has an option to enable the opposite behavior. Looks like your project has a shared inspection profile where someone enabled this inspection and turned off the "Require annotations to be sorted before keywords" option. You can go to Settings | Inspection and search for "Missorted modifiers" to disable the inspection or change how it reports warnings.

Upvotes: 0

Related Questions