Fix package tangle with configuration properties
Fix a package tangle that was introduced when we added cache bypass to `SpringIterableConfigurationPropertySource`. Ideally we should have been able to depend on `env` from `context` but unfortunately the `EnvironmentPostProcessor` interface references `SpringApplication` which needs to use the Binder. The `isImmutable` method has now been moved to `OriginLookup` which removes the immediate tangle. Closes gh-18393
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
||||
import org.springframework.boot.origin.OriginLookup;
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
@@ -236,8 +236,8 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope
|
||||
}
|
||||
|
||||
private static boolean isImmutable(EnumerablePropertySource<?> source) {
|
||||
if (source instanceof OriginTrackedMapPropertySource) {
|
||||
return ((OriginTrackedMapPropertySource) source).isImmutable();
|
||||
if (source instanceof OriginLookup) {
|
||||
return ((OriginLookup<?>) source).isImmutable();
|
||||
}
|
||||
if (StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME.equals(source.getName())) {
|
||||
return source.getSource() == System.getenv();
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.springframework.boot.origin.Origin;
|
||||
import org.springframework.boot.origin.OriginLookup;
|
||||
import org.springframework.boot.origin.OriginTrackedValue;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
/**
|
||||
* {@link OriginLookup} backed by a {@link Map} containing {@link OriginTrackedValue
|
||||
@@ -52,6 +51,7 @@ public final class OriginTrackedMapPropertySource extends MapPropertySource impl
|
||||
* @param name the property source name
|
||||
* @param source the underlying map source
|
||||
* @param immutable if the underlying source is immutable and guaranteed not to change
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public OriginTrackedMapPropertySource(String name, Map source, boolean immutable) {
|
||||
@@ -77,11 +77,7 @@ public final class OriginTrackedMapPropertySource extends MapPropertySource impl
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if this {@link PropertySource} is immutable and has contents
|
||||
* that will never change.
|
||||
* @return if the property source is read only
|
||||
*/
|
||||
@Override
|
||||
public boolean isImmutable() {
|
||||
return this.immutable;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,16 @@ public interface OriginLookup<K> {
|
||||
*/
|
||||
Origin getOrigin(K key);
|
||||
|
||||
/**
|
||||
* Return {@code true} if this lookup is immutable and has contents that will never
|
||||
* change.
|
||||
* @return if the lookup is immutable
|
||||
* @since 2.2.0
|
||||
*/
|
||||
default boolean isImmutable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to lookup the origin from the given source. If the source is not a
|
||||
* {@link OriginLookup} or if an exception occurs during lookup then {@code null} is
|
||||
|
||||
Reference in New Issue
Block a user