0

I have a static util method that I am calling with some values being null.

Here is the method signature that I am calling:

public static void logAndDisplayError(@Nullable Shell parentShell, String dialogTitle, String exceptionMessage, @Nullable Exception e, @Nullable Integer statusCode, boolean is1CD)

Here is the call to the method:

EclipseError.logAndDisplayError(getShell(), "Error Occured On Finish", message, null, null, true);

Inside the method, I am making a MessageDialog which is causing a null pointer.

Here is the MessageDialog creation:

MessageDialog dialog = new MessageDialog(parentShell, 
                dialogTitle, 
                MessageDialog.getImage(Dialog.DLG_IMG_MESSAGE_ERROR), 
                getErrorMessage(e.getMessage(), e, statusCode), 
                MessageDialog.ERROR, 
                new String[]{"1CD Help", "Ok"}, 
                1);

The null pointer is occuring on this call in the MessageDialog:

getErrorMessage(e.getMessage(), e, statusCode)

So we know that e and statusCode are null. But I have Nullable defined in the getErrorMessage method...

private static String getErrorMessage(String exceptionMessage, @Nullable Exception e, @Nullable Integer statusCode)

Why is it throwing the null pointer?

Also, here is the @Nullable I am using:

org.eclipse.jdt.annotation.Nullable

Chris Bolton
  • 2,162
  • 4
  • 36
  • 75

1 Answers1

0

As you see, it's an eclipse annotation and it's just like a little comment for developers. Method will always let you give a null parameter into it.

Since you give your method a null parameter it's natural to throw a NullPointerException

I suggest you to use make a bean and use hibernate validator for this purpose.

Hibernate validator is an implementation of bean validation.

Rg

Sercan Ozdemir
  • 4,641
  • 3
  • 34
  • 64