[java-shib-shared] 05/09: JSSH-71, IDP-2440 Remove the impact of the DestructableComponent Interface
Codeberg
noreply at shibboleth.net
Thu Jul 9 10:48:39 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
https://codeberg.org/Shibboleth/java-shib-shared/commit/90dcc7332e6933fd299d0fb70ab1d9bf0acdfc53
commit 90dcc7332e6933fd299d0fb70ab1d9bf0acdfc53
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Jul 6 15:34:15 2026 +0100
JSSH-71, IDP-2440 Remove the impact of the DestructableComponent Interface
https://shibboleth.atlassian.net/browse/JSSH-71
https://shibboleth.atlassian.net/browse/IDP-2440
Log an error message but do not throw an exception for use-after-destroy.
Remove a test that tested for that.
---
.../AbstractIdentifiedInitializableComponent.java | 8 +-
.../component/AbstractInitializableComponent.java | 28 ++++-
.../shared/xml/impl/BasicParserPoolTest.java | 127 ---------------------
3 files changed, 29 insertions(+), 134 deletions(-)
diff --git a/shib-support/src/main/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponent.java b/shib-support/src/main/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponent.java
index ce17bedb..4db8abb5 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponent.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponent.java
@@ -59,13 +59,11 @@ public abstract class AbstractIdentifiedInitializableComponent extends AbstractI
/**
* Checks if the component is destroyed and, if so, throws a {@link DestroyedComponentException}.
+ * @deprecated. This will be removed in V6.0
*/
+ @Deprecated(forRemoval = true, since = "5.3")
protected final void ifDestroyedThrowDestroyedComponentException() {
- if (isDestroyed()) {
- throw new DestroyedComponentException("Component '"
- + StringSupport.trimOrNull(getId())
- + "' has already been destroyed and can no longer be used.");
- }
+ super.ifDestroyedThrowDestroyedComponentException();
}
/**
diff --git a/shib-support/src/main/java/net/shibboleth/shared/component/AbstractInitializableComponent.java b/shib-support/src/main/java/net/shibboleth/shared/component/AbstractInitializableComponent.java
index aeb9aef9..f4279ce8 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/component/AbstractInitializableComponent.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/component/AbstractInitializableComponent.java
@@ -17,6 +17,10 @@ package net.shibboleth.shared.component;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
+import org.slf4j.Logger;
+
+import net.shibboleth.shared.primitive.LoggerFactory;
+
/** Base class for things that implement {@link DestructableComponent} and {@link InitializableComponent}. */
@ThreadSafe
public abstract class AbstractInitializableComponent implements DestructableComponent,
@@ -28,6 +32,9 @@ public abstract class AbstractInitializableComponent implements DestructableComp
/** Whether this component has been initialized. */
@GuardedBy("this") private boolean isInitialized;
+ /** Used for "user after teardown" warnings only */
+ private static Logger theLog;
+
/** {@inheritDoc} */
@Override
public final synchronized boolean isDestroyed() {
@@ -65,11 +72,17 @@ public abstract class AbstractInitializableComponent implements DestructableComp
/**
* Checks if the component is destroyed and, if so, throws a {@link DestroyedComponentException}.
+ * @deprecated. This will be removed in V6.0
*/
+ @Deprecated(forRemoval = true, since = "5.3")
protected void ifDestroyedThrowDestroyedComponentException() {
if (isDestroyed()) {
- throw new DestroyedComponentException(
- "Unidentified Component has already been destroyed and can no longer be used.");
+ if (this instanceof IdentifiedComponent) {
+ final String theName = ((IdentifiedComponent) this).getId();
+ getLog().warn("Component {} of type {} used after destroy", theName, this.getClass().getName());
+ } else {
+ getLog().warn("Anonymous component of type {} used after destroy", this.getClass().getName());
+ }
}
}
@@ -129,4 +142,15 @@ public abstract class AbstractInitializableComponent implements DestructableComp
protected void doInitialize() throws ComponentInitializationException {
}
+
+ /** Lazy init a logger.
+ * @return the logger.
+ */
+ private static Logger getLog() {
+ if (theLog == null) {
+ // One off busy-safe generate
+ theLog = LoggerFactory.getLogger(AbstractIdentifiedInitializableComponent.class);
+ }
+ return theLog;
+ }
}
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/impl/BasicParserPoolTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/impl/BasicParserPoolTest.java
index dc2e06d9..ae3ca073 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/impl/BasicParserPoolTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/impl/BasicParserPoolTest.java
@@ -343,133 +343,6 @@ public class BasicParserPoolTest {
basicParserPool.destroy();
}
-
- @Test public void testDestroy() throws ComponentInitializationException, SAXException, IOException {
- BasicParserPool pool = new BasicParserPool();
- pool.destroy();
-
- Boolean thrown = false;
- try {
- pool.initialize();
- } catch (DestroyedComponentException e) {
- thrown = true;
- } catch (ComponentInitializationException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "initialize after destroy");
-
- try {
- pool.setBuilderAttributes(new HashMap<String, Object>());
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setBuilderAttributes after destroy");
-
- thrown = false;
- try {
- pool.setBuilderFeatures(new HashMap<String, Boolean>());
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setBuilderFeatures after destroy");
-
- thrown = false;
-
- try {
- pool.setCoalescing(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setCoalescing after destroy");
-
- thrown = false;
- try {
- pool.setDTDValidating(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setDTDValidating after destroy");
-
- thrown = false;
- try {
- pool.setExpandEntityReferences(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setExpandEntityReferences after destroy");
-
- thrown = false;
- try {
- pool.setIgnoreComments(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setIgnoreComments after destroy");
-
- thrown = false;
- try {
- pool.setIgnoreElementContentWhitespace(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setIgnoreElementContentWhitespace after destroy");
-
- thrown = false;
- try {
- pool.setNamespaceAware(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setNamespaceAware after destroy");
-
- final Schema schema;
- try (final InputStream s = getClass().getResourceAsStream(SCHEMA_FILE)) {
- final SchemaBuilder schemaBuilder = new SchemaBuilder();
- schemaBuilder.addSchema(s);
- schema = schemaBuilder.buildSchema();
- }
-
- thrown = false;
- try {
- pool.setSchema(schema);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setSchema after destroy");
-
- thrown = false;
- try {
- pool.setXincludeAware(true);
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setXincludeAware after destroy");
-
- thrown = false;
- try {
- pool.setEntityResolver(new MockEntityResolver());
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setEntityResolver after destroy");
-
- thrown = false;
- try {
- pool.setErrorHandler(new MockErrorHandler());
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "setErrorHandler after destroy");
-
- thrown = false;
- try {
- pool.initialize();
- } catch (DestroyedComponentException e) {
- thrown = true;
- }
- Assert.assertTrue(thrown, "double initialize after destroy");
-
- }
private void checkParsedDocument(Document document) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list