Browse Source

Improve null-safety of loader/spring-boot-loader-tools

See gh-47263
pull/47665/head
Moritz Halbritter 4 months ago
parent
commit
e350286196
  1. 2
      loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java
  2. 16
      loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLibraryCoordinates.java
  3. 8
      loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryCoordinates.java
  4. 11
      loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java
  5. 4
      loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/layer/IncludeExcludeContentSelector.java

2
loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java

@ -58,7 +58,7 @@ public class DefaultLaunchScript implements LaunchScript { @@ -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);
}

16
loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLibraryCoordinates.java

@ -16,6 +16,8 @@ @@ -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; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -64,7 +66,7 @@ class DefaultLibraryCoordinates implements LibraryCoordinates {
* @return the version
*/
@Override
public String getVersion() {
public @Nullable String getVersion() {
return this.version;
}

8
loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryCoordinates.java

@ -31,19 +31,19 @@ public interface LibraryCoordinates { @@ -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 { @@ -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);
}

11
loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java

@ -173,7 +173,7 @@ public abstract class MainClassFinder { @@ -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 { @@ -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 { @@ -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 { @@ -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) {

4
loader/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/layer/IncludeExcludeContentSelector.java

@ -42,8 +42,8 @@ public class IncludeExcludeContentSelector<T> implements ContentSelector<T> { @@ -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());
}

Loading…
Cancel
Save