[java-identity-provider] branch main updated: Fix null and annotation issues.

Scott Cantor cantor.2 at osu.edu
Tue Nov 22 18:07:40 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=ad6fb86e153e96a24c76fab72a695012e15a6eaf

The following commit(s) were added to refs/heads/main by this push:
     new ad6fb86e1 Fix null and annotation issues.
ad6fb86e1 is described below

commit ad6fb86e153e96a24c76fab72a695012e15a6eaf
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Nov 22 13:07:37 2022 -0500

    Fix null and annotation issues.
---
 .../shibboleth/idp/metrics/impl/IdPGaugeSet.java   | 22 ++++++++++++++++++----
 .../idp/spring/DeprecatedPropertyBean.java         | 19 ++++++++++++++-----
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/IdPGaugeSet.java b/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/IdPGaugeSet.java
index 6731a8d06..e65bc0414 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/IdPGaugeSet.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/IdPGaugeSet.java
@@ -35,6 +35,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ApplicationObjectSupport;
 
 /**
@@ -72,7 +73,9 @@ public class IdPGaugeSet extends ApplicationObjectSupport implements MetricSet,
                 MetricRegistry.name(DEFAULT_METRIC_NAME, "starttime"),
                 new Gauge<Instant>() {
                     public Instant getValue() {
-                        return Instant.ofEpochMilli(getApplicationContext().getStartupDate());
+                        final ApplicationContext context = getApplicationContext();
+                        assert context != null;
+                        return Instant.ofEpochMilli(context.getStartupDate());
                     }
                 });
         
@@ -80,8 +83,10 @@ public class IdPGaugeSet extends ApplicationObjectSupport implements MetricSet,
                 MetricRegistry.name(DEFAULT_METRIC_NAME, "uptime"),
                 new Gauge<Duration>() {
                     public Duration getValue() {
+                        final ApplicationContext context = getApplicationContext();
+                        assert context != null;
                         return Duration.ofMillis(
-                                Instant.now().toEpochMilli() - getApplicationContext().getStartupDate());
+                                Instant.now().toEpochMilli() - context.getStartupDate());
                     }
                 });
     }
@@ -93,12 +98,15 @@ public class IdPGaugeSet extends ApplicationObjectSupport implements MetricSet,
      */
     public void setExposedProperties(@Nullable @NonnullElements final Set<String> properties) {
         if (properties != null) {
+            final ApplicationContext context = getApplicationContext();
+            assert context != null;
             for (final String property : properties) {
+                assert property != null;
                 gauges.put(
                         MetricRegistry.name(DEFAULT_METRIC_NAME, "properties", property),
                         new Gauge<String>() {
                             public String getValue() {
-                                return getApplicationContext().getEnvironment().getProperty(property);
+                                return context.getEnvironment().getProperty(property);
                             }
                         });
             }
@@ -114,5 +122,11 @@ public class IdPGaugeSet extends ApplicationObjectSupport implements MetricSet,
     public boolean matches(final String name, final Metric metric) {
         return gauges.containsKey(name);
     }
-    
+
+    /** {@inheritDoc} */
+    @Override
+    protected boolean isContextRequired() {
+        return true;
+    }
+
 }
\ No newline at end of file
diff --git a/idp-core/src/main/java/net/shibboleth/idp/spring/DeprecatedPropertyBean.java b/idp-core/src/main/java/net/shibboleth/idp/spring/DeprecatedPropertyBean.java
index fca2258f6..ba15e4b1b 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/spring/DeprecatedPropertyBean.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/spring/DeprecatedPropertyBean.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,7 +48,7 @@ public class DeprecatedPropertyBean extends AbstractInitializableComponent imple
     @Nonnull private final Logger log = LoggerFactory.getLogger(DeprecationSupport.LOG_CATEGORY);
     
     /** Spring context. */
-    @Nonnull private ApplicationContext applicationContext;
+    @Nullable private ApplicationContext applicationContext;
     
     /** Deprecated properties. */
     @Nonnull private Map<String,String> deprecatedProperties;
@@ -90,22 +91,30 @@ public class DeprecatedPropertyBean extends AbstractInitializableComponent imple
     }
 
     /** {@inheritDoc} */
-    public void setApplicationContext(final ApplicationContext context) {
+    public void setApplicationContext(@Nonnull final ApplicationContext context) {
         applicationContext = Constraint.isNotNull(context, "ApplicationContext cannot be null");
     }
     
     /** {@inheritDoc} */
     @Override
     protected void doInitialize() throws ComponentInitializationException {
+
+        final ApplicationContext context = applicationContext;
+        if (context == null) {
+            throw new ComponentInitializationException("ApplicationContext cannot be null");
+        }
         
         for (final Map.Entry<String,String> entry : deprecatedProperties.entrySet()) {
-            if (applicationContext.getEnvironment().containsProperty(entry.getKey())) {
-                DeprecationSupport.warn(ObjectType.PROPERTY, entry.getKey(), null, entry.getValue());
+            final String key = entry.getKey();
+            assert key != null;
+            if (context.getEnvironment().containsProperty(key)) {
+                DeprecationSupport.warn(ObjectType.PROPERTY, key, null, entry.getValue());
             }
         }
 
         for (final String name : deadProperties) {
-            if (applicationContext.getEnvironment().containsProperty(name)) {
+            assert name != null;
+            if (context.getEnvironment().containsProperty(name)) {
                 log.warn("property '{}' is no longer supported", name);
             }
         }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list