Not annotated parameter overrides @NotNull parameter | Community
Skip to main content
New Participant
July 5, 2023
Solved

Not annotated parameter overrides @NotNull parameter

  • July 5, 2023
  • 2 replies
  • 12854 views

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

Not annotated parameter overrides @126844 parameter

 

How can I deal with this?

 

Best answer by aanchal-sikka

 

@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

 

 

 

2 replies

New Participant
July 6, 2023

@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 }

aanchal-sikka
aanchal-sikkaAccepted solution
New Participant
July 5, 2023

 

@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