From 0e177ef281180a3e0fe33811f9691b78a5b812c3 Mon Sep 17 00:00:00 2001 From: Brian Flores Date: Tue, 31 Dec 2024 14:20:22 -0800 Subject: [PATCH] Adds check for Java 11 The test passes on JAVA 21 but for some reason Java 11 has trouble passing in a message so it returns null when getMessage occurs so when Mockito tries to invoke getMessage it will get get a second NPE. and thus is why the exception is caught. This code change is to get around the gap that Java 11 has. Signed-off-by: Brian Flores --- .../ml/processor/MLInferenceIngestProcessorTests.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/src/test/java/org/opensearch/ml/processor/MLInferenceIngestProcessorTests.java b/plugin/src/test/java/org/opensearch/ml/processor/MLInferenceIngestProcessorTests.java index 9a514c34a9..74e076eb0d 100644 --- a/plugin/src/test/java/org/opensearch/ml/processor/MLInferenceIngestProcessorTests.java +++ b/plugin/src/test/java/org/opensearch/ml/processor/MLInferenceIngestProcessorTests.java @@ -24,6 +24,7 @@ import org.junit.Assert; import org.junit.Before; import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -187,7 +188,10 @@ public void testExecute_xContentRegistryNullWithLocalModel_throwsException() thr argThat(exception -> exception instanceof NullPointerException && exception.getMessage().equals(npeMessage)) ); } catch (Exception e) { - assertEquals("this catch block should not get executed.", e.getMessage()); +// Java 11 doesn't pass the message correctly resulting in an anonymous NPE thus this getMessage() results in null + if (e.getMessage() != null) { + assertEquals("this catch block should not get executed.", e.getMessage()); + } } // reset to mocked object xContentRegistry = mock(NamedXContentRegistry.class);