mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-06 09:19:19 +00:00
Improve null-safety of loader/spring-boot-loader-tools
See gh-47263
This commit is contained in:
+1
-1
@@ -58,7 +58,7 @@ public class DefaultLaunchScript implements LaunchScript {
|
||||
* @param properties an optional set of script properties used for variable expansion
|
||||
* @throws IOException if the script cannot be loaded
|
||||
*/
|
||||
public DefaultLaunchScript(@Nullable File file, Map<?, ?> properties) throws IOException {
|
||||
public DefaultLaunchScript(@Nullable File file, @Nullable Map<?, ?> properties) throws IOException {
|
||||
String content = loadContent(file);
|
||||
this.content = expandPlaceholders(content, properties);
|
||||
}
|
||||
|
||||
+9
-7
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.loader.tools;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Encapsulates information about the artifact coordinates of a library.
|
||||
*
|
||||
@@ -23,11 +25,11 @@ package org.springframework.boot.loader.tools;
|
||||
*/
|
||||
class DefaultLibraryCoordinates implements LibraryCoordinates {
|
||||
|
||||
private final String groupId;
|
||||
private final @Nullable String groupId;
|
||||
|
||||
private final String artifactId;
|
||||
private final @Nullable String artifactId;
|
||||
|
||||
private final String version;
|
||||
private final @Nullable String version;
|
||||
|
||||
/**
|
||||
* Create a new instance from discrete elements.
|
||||
@@ -35,7 +37,7 @@ class DefaultLibraryCoordinates implements LibraryCoordinates {
|
||||
* @param artifactId the artifact ID
|
||||
* @param version the version
|
||||
*/
|
||||
DefaultLibraryCoordinates(String groupId, String artifactId, String version) {
|
||||
DefaultLibraryCoordinates(@Nullable String groupId, @Nullable String artifactId, @Nullable String version) {
|
||||
this.groupId = groupId;
|
||||
this.artifactId = artifactId;
|
||||
this.version = version;
|
||||
@@ -46,7 +48,7 @@ class DefaultLibraryCoordinates implements LibraryCoordinates {
|
||||
* @return the group ID
|
||||
*/
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
public @Nullable String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ class DefaultLibraryCoordinates implements LibraryCoordinates {
|
||||
* @return the artifact ID
|
||||
*/
|
||||
@Override
|
||||
public String getArtifactId() {
|
||||
public @Nullable String getArtifactId() {
|
||||
return this.artifactId;
|
||||
}
|
||||
|
||||
@@ -64,7 +66,7 @@ class DefaultLibraryCoordinates implements LibraryCoordinates {
|
||||
* @return the version
|
||||
*/
|
||||
@Override
|
||||
public String getVersion() {
|
||||
public @Nullable String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -31,19 +31,19 @@ public interface LibraryCoordinates {
|
||||
* Return the group ID of the coordinates.
|
||||
* @return the group ID
|
||||
*/
|
||||
String getGroupId();
|
||||
@Nullable String getGroupId();
|
||||
|
||||
/**
|
||||
* Return the artifact ID of the coordinates.
|
||||
* @return the artifact ID
|
||||
*/
|
||||
String getArtifactId();
|
||||
@Nullable String getArtifactId();
|
||||
|
||||
/**
|
||||
* Return the version of the coordinates.
|
||||
* @return the version
|
||||
*/
|
||||
String getVersion();
|
||||
@Nullable String getVersion();
|
||||
|
||||
/**
|
||||
* Factory method to create {@link LibraryCoordinates} with the specified values.
|
||||
@@ -52,7 +52,7 @@ public interface LibraryCoordinates {
|
||||
* @param version the version
|
||||
* @return a new {@link LibraryCoordinates} instance
|
||||
*/
|
||||
static LibraryCoordinates of(String groupId, String artifactId, String version) {
|
||||
static LibraryCoordinates of(@Nullable String groupId, @Nullable String artifactId, @Nullable String version) {
|
||||
return new DefaultLibraryCoordinates(groupId, artifactId, version);
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -173,7 +173,7 @@ public abstract class MainClassFinder {
|
||||
* @return the main class or {@code null}
|
||||
* @throws IOException if the jar file cannot be read
|
||||
*/
|
||||
public static @Nullable String findMainClass(JarFile jarFile, String classesLocation) throws IOException {
|
||||
public static @Nullable String findMainClass(JarFile jarFile, @Nullable String classesLocation) throws IOException {
|
||||
return doWithMainClasses(jarFile, classesLocation, MainClass::getName);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,8 @@ public abstract class MainClassFinder {
|
||||
* @return the main class or {@code null}
|
||||
* @throws IOException if the jar file cannot be read
|
||||
*/
|
||||
public static @Nullable String findSingleMainClass(JarFile jarFile, String classesLocation) throws IOException {
|
||||
public static @Nullable String findSingleMainClass(JarFile jarFile, @Nullable String classesLocation)
|
||||
throws IOException {
|
||||
return findSingleMainClass(jarFile, classesLocation, null);
|
||||
}
|
||||
|
||||
@@ -199,7 +200,7 @@ public abstract class MainClassFinder {
|
||||
* @return the main class or {@code null}
|
||||
* @throws IOException if the jar file cannot be read
|
||||
*/
|
||||
public static @Nullable String findSingleMainClass(JarFile jarFile, String classesLocation,
|
||||
public static @Nullable String findSingleMainClass(JarFile jarFile, @Nullable String classesLocation,
|
||||
@Nullable String annotationName) throws IOException {
|
||||
SingleMainClassCallback callback = new SingleMainClassCallback(annotationName);
|
||||
MainClassFinder.doWithMainClasses(jarFile, classesLocation, callback);
|
||||
@@ -215,8 +216,8 @@ public abstract class MainClassFinder {
|
||||
* @return the first callback result or {@code null}
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
static <T> @Nullable T doWithMainClasses(JarFile jarFile, String classesLocation, MainClassCallback<T> callback)
|
||||
throws IOException {
|
||||
static <T> @Nullable T doWithMainClasses(JarFile jarFile, @Nullable String classesLocation,
|
||||
MainClassCallback<T> callback) throws IOException {
|
||||
List<JarEntry> classEntries = getClassEntries(jarFile, classesLocation);
|
||||
classEntries.sort(new ClassEntryComparator());
|
||||
for (JarEntry entry : classEntries) {
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ public class IncludeExcludeContentSelector<T> implements ContentSelector<T> {
|
||||
|
||||
private final List<ContentFilter<T>> excludes;
|
||||
|
||||
public IncludeExcludeContentSelector(Layer layer, List<ContentFilter<T>> includes,
|
||||
List<ContentFilter<T>> excludes) {
|
||||
public IncludeExcludeContentSelector(Layer layer, @Nullable List<ContentFilter<T>> includes,
|
||||
@Nullable List<ContentFilter<T>> excludes) {
|
||||
this(layer, includes, excludes, Function.identity());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user