From 24aa6163f00d02b546a33d99e888068054c6aba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Fri, 3 Nov 2023 12:10:01 +0100 Subject: [PATCH] Polish --- .../aot/generate/AppendableConsumerInputStreamSource.java | 5 ++--- .../aot/hint/BindingReflectionHintsRegistrar.java | 2 +- .../java/org/springframework/aot/hint/MemberCategory.java | 2 +- .../springframework/aot/hint/ResourcePatternHints.java | 4 ++-- .../aot/hint/support/KotlinDetectorRuntimeHints.java | 3 ++- .../PathMatchingResourcePatternResolverRuntimeHints.java | 3 ++- .../hint/support/SpringFactoriesLoaderRuntimeHints.java | 8 +++++--- .../springframework/aot/nativex/ResourceHintsWriter.java | 6 +++--- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/generate/AppendableConsumerInputStreamSource.java b/spring-core/src/main/java/org/springframework/aot/generate/AppendableConsumerInputStreamSource.java index faf34eb53d..fab5a7460c 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/AppendableConsumerInputStreamSource.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/AppendableConsumerInputStreamSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -17,7 +17,6 @@ package org.springframework.aot.generate; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -42,7 +41,7 @@ class AppendableConsumerInputStreamSource implements InputStreamSource { @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { return new ByteArrayInputStream(toString().getBytes(StandardCharsets.UTF_8)); } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java index 806229cb4e..7a9560af42 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java @@ -187,7 +187,7 @@ public class BindingReflectionHintsRegistrar { .from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY) .stream(JACKSON_ANNOTATION) .filter(MergedAnnotation::isMetaPresent) - .forEach(action::accept); + .forEach(action); } private void registerHintsForClassAttributes(ReflectionHints hints, MergedAnnotation annotation) { diff --git a/spring-core/src/main/java/org/springframework/aot/hint/MemberCategory.java b/spring-core/src/main/java/org/springframework/aot/hint/MemberCategory.java index 9424b17f9a..2d09bb0e45 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/MemberCategory.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/MemberCategory.java @@ -124,6 +124,6 @@ public enum MemberCategory { * reflection for inner classes but rather makes sure they are available * via a call to {@link Class#getDeclaredClasses}. */ - DECLARED_CLASSES; + DECLARED_CLASSES } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java b/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java index 876f6a3fe9..78c8ce9a6e 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -143,7 +143,7 @@ public final class ResourcePatternHints { * @param excludes the exclude patterns (see {@link ResourcePatternHint} documentation) * @return {@code this}, to facilitate method chaining */ - public Builder excludes(TypeReference reachableType, String... excludes) { + public Builder excludes(@Nullable TypeReference reachableType, String... excludes) { List newExcludes = Arrays.stream(excludes) .map(include -> new ResourcePatternHint(include, reachableType)).toList(); this.excludes.addAll(newExcludes); diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java index 5270f16b95..ed820c4a15 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java @@ -19,6 +19,7 @@ package org.springframework.aot.hint.support; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; +import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for {@link org.springframework.core.KotlinDetector}. @@ -29,7 +30,7 @@ import org.springframework.aot.hint.TypeReference; class KotlinDetectorRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.reflection().registerType(TypeReference.of("kotlin.Metadata")) .registerType(TypeReference.of("kotlin.reflect.full.KClasses")); } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java index d5791f7056..371812e06c 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java @@ -20,6 +20,7 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} for {@link PathMatchingResourcePatternResolver}. @@ -28,7 +29,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; class PathMatchingResourcePatternResolverRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.reflection().registerType(TypeReference.of("org.eclipse.core.runtime.FileLocator")); } } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java index 9d8318e438..a25287e198 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -47,9 +47,11 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + ClassLoader classLoaderToUse = (classLoader != null ? classLoader + : SpringFactoriesLoaderRuntimeHints.class.getClassLoader()); for (String resourceLocation : RESOURCE_LOCATIONS) { - registerHints(hints, classLoader, resourceLocation); + registerHints(hints, classLoaderToUse, resourceLocation); } } diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/ResourceHintsWriter.java b/spring-core/src/main/java/org/springframework/aot/nativex/ResourceHintsWriter.java index cdbaba7884..8db578d952 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/ResourceHintsWriter.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/ResourceHintsWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -60,8 +60,8 @@ class ResourceHintsWriter { return attributes; } - private void handleResourceBundles(Map attributes, Stream ressourceBundles) { - addIfNotEmpty(attributes, "bundles", ressourceBundles.map(this::toAttributes).toList()); + private void handleResourceBundles(Map attributes, Stream resourceBundles) { + addIfNotEmpty(attributes, "bundles", resourceBundles.map(this::toAttributes).toList()); } private Map toAttributes(ResourceBundleHint hint) {