Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Not annotated parameter overrides @NotNull parameter

Avatar

Level 5

I'm working on a servlet. And the response argument is throwing the below sonar issue.

Not annotated parameter overrides @notnull parameter

 

How can I deal with this?

goyalkritika_0-1688533996050.png

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

 

@goyalkritika 

this annotation means that the parent method has some @NotNull / @NonNull annotation on the parameter, while the overriding method has no.

To fix it, you need to put the same annotation on the overriding method.

 

Please try

 

import org.jetbrains.annotations.NotNull;

 

 

 @Override
    protected void doGet(final @NotNull SlingHttpServletRequest request,
                         final @NotNull SlingHttpServletResponse response) throws ServletException, IOException 

 

 

 


Aanchal Sikka

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

 

@goyalkritika 

this annotation means that the parent method has some @NotNull / @NonNull annotation on the parameter, while the overriding method has no.

To fix it, you need to put the same annotation on the overriding method.

 

Please try

 

import org.jetbrains.annotations.NotNull;

 

 

 @Override
    protected void doGet(final @NotNull SlingHttpServletRequest request,
                         final @NotNull SlingHttpServletResponse response) throws ServletException, IOException 

 

 

 


Aanchal Sikka

Avatar

Level 1

@goyalkritika The Sonar issue you mentioned, "Not annotated parameter overrides @NotNull parameter," indicates that you have a method in your servlet that overrides a method from a superclass or interface, and the overridden method has a parameter annotated with @NotNull to indicate that it cannot be null. However, in your overriding method, you have not provided the @NotNull annotation for the corresponding parameter.

Here's an example of how you can add the @NotNull annotation to your parameter in the servlet method:

@Override
public void doGet(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)

{ // Servlet code }