mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 20:19:06 +00:00
Fix "String.startsWith(String)" NPE when refreshing in eclipse
Fix NPE triggered by `PropertiesPersistableConfigurationObject` having no `getDefaultResourceName()`. See gh-48929
This commit is contained in:
@@ -40,22 +40,22 @@ class EclipseConventions {
|
||||
|
||||
void apply(Project project) {
|
||||
project.getPlugins().withType(EclipsePlugin.class, (eclipse) -> configure(project, eclipse));
|
||||
project.afterEvaluate(this::setJavaRuntimeName);
|
||||
}
|
||||
|
||||
private DomainObjectCollection<JavaBasePlugin> configure(Project project, EclipsePlugin eclipsePlugin) {
|
||||
TaskProvider<EclipseSynchronizeJdtSettings> eclipseSynchronizeJdtSettings = registerEclipseSynchronizeJdtSettingsTask(
|
||||
project);
|
||||
TaskProvider<?> synchronizeJdtSettings = registerEclipseSynchronizeJdtSettings(project);
|
||||
return project.getPlugins().withType(JavaBasePlugin.class, (javaBase) -> {
|
||||
EclipseModel model = project.getExtensions().getByType(EclipseModel.class);
|
||||
model.synchronizationTasks(eclipseSynchronizeJdtSettings);
|
||||
model.synchronizationTasks(synchronizeJdtSettings);
|
||||
model.jdt(this::configureJdt);
|
||||
model.classpath(this::configureClasspath);
|
||||
});
|
||||
}
|
||||
|
||||
private TaskProvider<EclipseSynchronizeJdtSettings> registerEclipseSynchronizeJdtSettingsTask(Project project) {
|
||||
private TaskProvider<EclipseSynchronizeJdtSettings> registerEclipseSynchronizeJdtSettings(Project project) {
|
||||
TaskProvider<EclipseSynchronizeJdtSettings> taskProvider = project.getTasks()
|
||||
.register("eclipseSynchronizateJdt", EclipseSynchronizeJdtSettings.class);
|
||||
.register("eclipseSynchronizeJdtSettings", EclipseSynchronizeJdtSettings.class);
|
||||
taskProvider.configure((task) -> {
|
||||
task.setDescription("Synchronizate the Eclipse JDT settings file from Buildship.");
|
||||
task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
|
||||
@@ -82,6 +82,14 @@ class EclipseConventions {
|
||||
});
|
||||
}
|
||||
|
||||
private void setJavaRuntimeName(Project project) {
|
||||
EclipseModel model = project.getExtensions().findByType(EclipseModel.class);
|
||||
EclipseJdt jdt = (model != null) ? model.getJdt() : null;
|
||||
if (jdt != null) {
|
||||
model.getJdt().setJavaRuntimeName("JavaSE-" + JavaConventions.RUNTIME_JAVA_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isKotlinPluginContributedBuildDirectory(ClasspathEntry entry) {
|
||||
return (entry instanceof Library library) && isKotlinPluginContributedBuildDirectory(library.getPath())
|
||||
&& isTest(library);
|
||||
|
||||
+1
-11
@@ -21,7 +21,6 @@ import java.util.Properties;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.internal.PropertiesTransformer;
|
||||
import org.gradle.plugins.ide.api.PropertiesGeneratorTask;
|
||||
import org.gradle.plugins.ide.internal.generator.PropertiesPersistableConfigurationObject;
|
||||
|
||||
import org.springframework.boot.build.EclipseSynchronizeJdtSettings.Configuration;
|
||||
|
||||
@@ -41,21 +40,12 @@ public abstract class EclipseSynchronizeJdtSettings extends PropertiesGeneratorT
|
||||
protected void configure(Configuration configuration) {
|
||||
}
|
||||
|
||||
static class Configuration extends PropertiesPersistableConfigurationObject {
|
||||
static class Configuration extends EmptyPropertiesPersistableConfigurationObject {
|
||||
|
||||
Configuration(PropertiesTransformer transformer) {
|
||||
super(transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultResourceName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(Properties properties) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void store(Properties properties) {
|
||||
properties.put("org.eclipse.jdt.core.compiler.release", "true");
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gradle.api.internal.PropertiesTransformer;
|
||||
import org.gradle.internal.UncheckedException;
|
||||
import org.gradle.plugins.ide.internal.generator.PropertiesPersistableConfigurationObject;
|
||||
|
||||
/**
|
||||
* Base class for {@link PropertiesPersistableConfigurationObject} instances start empty
|
||||
* and have no default resource.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
abstract class EmptyPropertiesPersistableConfigurationObject extends PropertiesPersistableConfigurationObject {
|
||||
|
||||
EmptyPropertiesPersistableConfigurationObject(PropertiesTransformer transformer) {
|
||||
super(transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultResourceName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDefaults() {
|
||||
try {
|
||||
load(new ByteArrayInputStream(new byte[0]));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw UncheckedException.throwAsUncheckedException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(Properties properties) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user