From d292364cc285052226384082f5304465ffbbe475 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Tue, 20 Feb 2024 20:34:41 +0100 Subject: [PATCH] Set o.e.j.c.compiler.problem.nullUncheckedConversion to ignore by default Signed-off-by: Snjezana Peco --- .../internal/preferences/Preferences.java | 2 ++ .../preferences/NullAnalysisTest.java | 19 +++++++++++++++---- .../preferences/PreferenceManagerTest.java | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java index d3721fb139..a2acd1e941 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java @@ -2509,6 +2509,7 @@ private Map generateProjectNullAnalysisOptions(String nonnullTyp options.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, defaultOptions.get(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); options.put(JavaCore.COMPILER_PB_NULL_ANNOTATION_INFERENCE_CONFLICT, defaultOptions.get(JavaCore.COMPILER_PB_NULL_ANNOTATION_INFERENCE_CONFLICT)); options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, defaultOptions.get(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS)); + options.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, defaultOptions.get(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); } else { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, "enabled"); options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, nonnullType != null ? nonnullType : ""); @@ -2520,6 +2521,7 @@ private Map generateProjectNullAnalysisOptions(String nonnullTyp options.put(JavaCore.COMPILER_PB_NULL_ANNOTATION_INFERENCE_CONFLICT, "warning"); options.put(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, "ignore"); options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.IGNORE); } return options; } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/NullAnalysisTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/NullAnalysisTest.java index 79bd9af51a..ddce1d54ae 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/NullAnalysisTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/NullAnalysisTest.java @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.util.Collections; +import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -106,12 +107,21 @@ public void testMixedNullAnalysis() throws Exception { assertTrue(marker.getResource() instanceof IFile); assertEquals("TestJDT.java", ((IFile) marker1.getResource()).getFullPath().lastSegment()); IMarker marker2 = getWarningMarker(project, "The return type is incompatible with '@Nonnull String' returned from TestJavax.A.nonnullMethod() (mismatching null constraints)"); - assertNotNull(marker); - assertTrue(marker.getResource() instanceof IFile); + assertNotNull(marker2); + assertTrue(marker2.getResource() instanceof IFile); assertEquals("TestJavax.java", ((IFile) marker2.getResource()).getFullPath().lastSegment()); IMarker marker3 = getWarningMarker(project, "Null type safety: The expression of type 'List' needs unchecked conversion to conform to '@Nonnull List'"); - assertNotNull(marker); - assertTrue(marker.getResource() instanceof IFile); + assertNull(marker3); + IJavaProject javaProject = JavaCore.create(project); + Map options = javaProject.getOptions(true); + assertEquals(JavaCore.IGNORE, options.get(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + Hashtable defaultOptions = JavaCore.getDefaultOptions(); + options.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, defaultOptions.get(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + javaProject.setOptions(options); + waitForBackgroundJobs(); + marker3 = getWarningMarker(project, "Null type safety: The expression of type 'List' needs unchecked conversion to conform to '@Nonnull List'"); + assertNotNull(marker3); + assertTrue(marker3.getResource() instanceof IFile); assertEquals("TestJavax.java", ((IFile) marker3.getResource()).getFullPath().lastSegment()); assertNoErrors(project); } finally { @@ -216,4 +226,5 @@ public void testNonnullbyDefault() throws Exception { this.preferenceManager.getPreferences().updateAnnotationNullAnalysisOptions(); } } + } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/PreferenceManagerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/PreferenceManagerTest.java index 32bd377a88..add7cb37ba 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/PreferenceManagerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/preferences/PreferenceManagerTest.java @@ -379,4 +379,5 @@ public void testTelemetrySettings() throws Exception { assertEquals(false, preferenceManager.getPreferences().isTelemetryEnabled()); } } + }