From e4520afa219ae8585bc7b7d0fb73cbf3bfb8d7ce Mon Sep 17 00:00:00 2001 From: Benjamin Confino Date: Thu, 5 Dec 2024 21:22:18 +0000 Subject: [PATCH] refactor to make app keys an input to ClassSource_Factory --- .../internal/ClassSourceImpl_Aggregate.java | 30 +- .../internal/ClassSourceImpl_Factory.java | 10 +- .../ClassSourceImpl_Specification.java | 13 +- .../internal/TargetCacheImpl_DataApps.java | 2 +- .../AnnotationTargetsImpl_Targets.java | 9 +- .../service/AnnotationService_KeyService.java | 50 --- .../com/ibm/wsspi/anno/service/AppKey.java | 39 ++ .../classsource/ClassSource_Aggregate.java | 2 +- .../classsource/ClassSource_Factory.java | 12 +- .../test/info/InfoStore_Internals_Test.java | 10 +- .../test/info/InfoStore_TestBase.java | 9 +- ...AnnotationMixed_war_SimpleSource_Test.java | 13 +- ...Method_StaticAnnotationMixed_war_Test.java | 6 +- ...nMethod_StaticAnnotationPure_war_Test.java | 6 +- ...ethod_StaticAnnotationWebXML_war_Test.java | 6 +- .../SCITest_SCIAbsoluteNoOthers_war_Test.java | 6 +- .../samples/SCITest_SCIAbsolute_war_Test.java | 6 +- .../AnnotationService_KeyService.java | 20 + .../annocache/internal/AnnotationsImpl.java | 357 +++++++++--------- .../internal/ApplicationKeyServiceImpl.java | 10 +- 20 files changed, 326 insertions(+), 290 deletions(-) delete mode 100644 dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AnnotationService_KeyService.java create mode 100644 dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AppKey.java create mode 100644 dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationService_KeyService.java diff --git a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java index 1cb1bd80ff01..b4eb22f4ebc0 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java @@ -16,8 +16,6 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; import java.text.MessageFormat; import java.util.ArrayList; @@ -26,7 +24,6 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -35,17 +32,14 @@ import com.ibm.websphere.ras.TraceComponent; import com.ibm.websphere.ras.annotation.Trivial; import com.ibm.ws.annocache.service.internal.AnnotationCacheServiceImpl_Logging; -import com.ibm.ws.kernel.service.util.ServiceCaller; import com.ibm.wsspi.anno.classsource.ClassSource_ScanCounts; import com.ibm.wsspi.anno.classsource.ClassSource_ScanCounts.ResultField; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.anno.classsource.ClassSource_Streamer; -import com.ibm.wsspi.anno.service.AnnotationService_KeyService; -import com.ibm.wsspi.anno.service.AnnotationService_KeyService.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; import com.ibm.wsspi.annocache.classsource.ClassSource_ClassLoader; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; -import com.ibm.wsspi.annocache.classsource.ClassSource_Factory; import com.ibm.wsspi.annocache.classsource.ClassSource_Options; import com.ibm.wsspi.annocache.util.Util_InternMap; @@ -70,9 +64,6 @@ public class ClassSourceImpl_Aggregate implements ClassSource_Aggregate { public static final String CLASS_NAME = ClassSourceImpl_Aggregate.class.getSimpleName(); // Logging ... - - private static final ServiceCaller keyServiceServiceCaller = new ServiceCaller(ClassSourceImpl_Aggregate.class, - AnnotationService_KeyService.class); protected final String hashText; @@ -91,11 +82,11 @@ public String toString() { // // Top O' the world - + public ClassSourceImpl_Aggregate( ClassSourceImpl_Factory factory, Util_InternMap internMap, - String applicationName, String moduleName, String moduleCategoryName, + String applicationName, AppKey appKey, String moduleName, String moduleCategoryName, ClassSource_Options options) { String methodName = ""; @@ -109,18 +100,7 @@ public ClassSourceImpl_Aggregate( this.applicationName = applicationName; this.moduleName = moduleName; this.moduleCategoryName = moduleCategoryName; - - Properties props = System.getProperties(); - String inUnitTest = props.getProperty("running.unit.test"); - - if (inUnitTest != null && inUnitTest.equals("true")) { - this.applicationKey = new SoftReference(new AppKey(applicationName)); - } else if (applicationName != ClassSource_Factory.UNNAMED_APP) { - AppKey appKey = keyServiceServiceCaller.run((AnnotationService_KeyService ks) -> ks.getKeyForApp(applicationName)).get(); - this.applicationKey = new WeakReference(appKey); - } else { - this.applicationKey = new WeakReference(null); - } + this.applicationKey = new WeakReference(appKey); // @@ -202,7 +182,7 @@ protected String internClassName(String className, boolean doForce) { protected final String applicationName; protected final String moduleName; protected final String moduleCategoryName; - protected final Reference applicationKey; + protected final WeakReference applicationKey; /** *

Answer the name of the application of this class source.

diff --git a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Factory.java b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Factory.java index 256f613048aa..7c8114e533b0 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Factory.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Factory.java @@ -39,6 +39,7 @@ import com.ibm.wsspi.anno.classsource.ClassSource_MappedDirectory; import com.ibm.wsspi.anno.classsource.ClassSource_MappedJar; import com.ibm.wsspi.anno.classsource.ClassSource_MappedSimple.SimpleClassProvider; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate.ScanPolicy; import com.ibm.wsspi.annocache.classsource.ClassSource_ClassLoader; @@ -46,7 +47,6 @@ import com.ibm.wsspi.annocache.classsource.ClassSource_Factory; import com.ibm.wsspi.annocache.classsource.ClassSource_MappedSimple; import com.ibm.wsspi.annocache.classsource.ClassSource_Options; -import com.ibm.wsspi.annocache.service.AnnotationCacheService_Service; import com.ibm.wsspi.annocache.util.Util_Factory; import com.ibm.wsspi.annocache.util.Util_InternMap; import com.ibm.wsspi.annocache.util.Util_RelativePath; @@ -166,13 +166,13 @@ public String getCanonicalName(String classSourceName) { @Override @Trivial public ClassSourceImpl_Aggregate createAggregateClassSource( - String appName, String modName, String modCategoryName, + String appName, AppKey appKey, String modName, String modCategoryName, ClassSource_Options options) throws ClassSource_Exception { Util_InternMap classInternMap = getUtilFactory().createInternMap(Util_InternMap.ValueType.VT_CLASS_NAME, "classes and packages"); - return createAggregateClassSource(classInternMap, appName, modName, modCategoryName, options); + return createAggregateClassSource(classInternMap, appName, appKey, modName, modCategoryName, options); // throws ClassSource_Exception } @@ -283,10 +283,10 @@ public ClassSourceImpl_ClassLoader createClassLoaderClassSource( @Override public ClassSourceImpl_Aggregate createAggregateClassSource( Util_InternMap internMap, - String appName, String modName, String modCategoryName, + String appName, AppKey appKey, String modName, String modCategoryName, ClassSource_Options options) throws ClassSource_Exception { - return new ClassSourceImpl_Aggregate(this, internMap, appName, modName, modCategoryName, options); + return new ClassSourceImpl_Aggregate(this, internMap, appName, appKey, modName, modCategoryName, options); } @Override diff --git a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/specification/internal/ClassSourceImpl_Specification.java b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/specification/internal/ClassSourceImpl_Specification.java index df8334ba5d8e..8cd2ce898c29 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/specification/internal/ClassSourceImpl_Specification.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/specification/internal/ClassSourceImpl_Specification.java @@ -16,12 +16,6 @@ import java.util.logging.Logger; import com.ibm.websphere.ras.annotation.Trivial; - -import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; -import com.ibm.wsspi.annocache.classsource.ClassSource_Options; -import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; -import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate.ScanPolicy; - import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_ClassLoader; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Factory; @@ -29,6 +23,11 @@ import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_MappedJar; import com.ibm.ws.annocache.classsource.specification.ClassSource_Specification; import com.ibm.ws.annocache.service.internal.AnnotationCacheServiceImpl_Logging; +import com.ibm.wsspi.anno.service.AppKey; +import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; +import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate.ScanPolicy; +import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; +import com.ibm.wsspi.annocache.classsource.ClassSource_Options; public abstract class ClassSourceImpl_Specification implements ClassSource_Specification { @@ -134,7 +133,7 @@ public ClassSourceImpl_Aggregate createEmptyRootClassSource(ClassSource_Options throws ClassSource_Exception { return getFactory().createAggregateClassSource( - getAppName(), getModName(), getModCategoryName(), + getAppName(), new AppKey(getAppName()), getModName(), getModCategoryName(), classSourceOptions ); } diff --git a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/cache/internal/TargetCacheImpl_DataApps.java b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/cache/internal/TargetCacheImpl_DataApps.java index 4426e4a293df..02717e0c2f4b 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/cache/internal/TargetCacheImpl_DataApps.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/cache/internal/TargetCacheImpl_DataApps.java @@ -16,7 +16,7 @@ import java.util.WeakHashMap; import com.ibm.websphere.ras.annotation.Trivial; -import com.ibm.wsspi.anno.service.AnnotationService_KeyService.AppKey; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Factory; import com.ibm.wsspi.annocache.targets.cache.TargetCache_ExternalConstants; import com.ibm.wsspi.annocache.targets.cache.TargetCache_Options; diff --git a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/internal/AnnotationTargetsImpl_Targets.java b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/internal/AnnotationTargetsImpl_Targets.java index c343d7fb647d..77fa0c51ddb2 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/internal/AnnotationTargetsImpl_Targets.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/targets/internal/AnnotationTargetsImpl_Targets.java @@ -12,6 +12,7 @@ *******************************************************************************/ package com.ibm.ws.annocache.targets.internal; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -39,7 +40,7 @@ import com.ibm.ws.annocache.util.internal.UtilImpl_NonInternSet; import com.ibm.ws.annocache.util.internal.UtilImpl_Utils; import com.ibm.wsspi.anno.classsource.ClassSource_Aggregate.ScanPolicy; -import com.ibm.wsspi.anno.service.AnnotationService_KeyService.AppKey; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.anno.util.Util_InternMap.ValueType; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; import com.ibm.wsspi.annocache.targets.AnnotationTargets_Exception; @@ -463,7 +464,7 @@ protected void putSpecificResults(TargetsScannerBaseImpl scanner) { protected ClassSource_Aggregate rootClassSource; protected String appName; - protected AppKey appKey; + protected WeakReference appKey; protected String modName; protected String modCatName; protected String modFullName; @@ -476,7 +477,7 @@ protected void setRootClassSource(ClassSource_Aggregate rootClassSource) { protected void setNames(ClassSource_Aggregate useRootClassSource) { this.appName = useRootClassSource.getApplicationName(); - this.appKey = useRootClassSource.getApplicationKey(); + this.appKey = new WeakReference(useRootClassSource.getApplicationKey()); this.modName = useRootClassSource.getModuleName(); this.modCatName = useRootClassSource.getModuleCategoryName(); @@ -501,7 +502,7 @@ public String getAppName() { @Trivial public AppKey getAppKey() { - return appKey; + return appKey.get(); } @Trivial diff --git a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AnnotationService_KeyService.java b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AnnotationService_KeyService.java deleted file mode 100644 index d19791b05923..000000000000 --- a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AnnotationService_KeyService.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ibm.wsspi.anno.service; - -import java.util.Optional; - -/** - * This service provides keys with a 1:1 mapping to each application installed. - * These keys can be used in a WeakHashMap to ensure the value is garbage collected - * when the application shuts down - */ -public interface AnnotationService_KeyService { - - /** - * Gets an AppKey for a given application - * - * @param appName the name of the application, this must be the deploymentName from com.ibm.ws.container.service.app.deploy.ApplicationInfo - * @return An AppKey for the given appName, or null if no key was found. - */ - public AnnotationService_KeyService.AppKey getKeyForApp(String appName); - - public class AppKey { - private final String deploymentName; - - public AppKey(String deploymentName) { - this.deploymentName = deploymentName; - } - - public String getDeploymentName() { - return deploymentName; - } - - @Override - public int hashCode() { - return deploymentName.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AppKey other = (AppKey) obj; - - return deploymentName.equals(other.getDeploymentName()); - } - } - -} \ No newline at end of file diff --git a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AppKey.java b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AppKey.java new file mode 100644 index 000000000000..ad1ad904b9de --- /dev/null +++ b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/anno/service/AppKey.java @@ -0,0 +1,39 @@ +package com.ibm.wsspi.anno.service; + +public class AppKey { + private final String deploymentName; + + public AppKey(String deploymentName) { + this.deploymentName = deploymentName; + } + + public String getDeploymentName() { + return deploymentName; + } + + @Override + public int hashCode() { + if (deploymentName == null) { + return 0; + } + + return deploymentName.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AppKey other = (AppKey) obj; + + if (deploymentName == null) { + return other.getDeploymentName() == null; + } + + return deploymentName.equals(other.getDeploymentName()); + } +} \ No newline at end of file diff --git a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Aggregate.java b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Aggregate.java index eee2e044bf51..57563cbd65d9 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Aggregate.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Aggregate.java @@ -20,7 +20,7 @@ import java.util.Set; import java.util.logging.Logger; -import com.ibm.wsspi.anno.service.AnnotationService_KeyService.AppKey; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.util.Util_InternMap; /** diff --git a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Factory.java b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Factory.java index 32a8b547b0de..b19e91ee6384 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Factory.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/wsspi/annocache/classsource/ClassSource_Factory.java @@ -18,6 +18,7 @@ import com.ibm.ws.annocache.classsource.specification.ClassSource_Specification_Element; import com.ibm.ws.annocache.classsource.specification.ClassSource_Specification_Elements; import com.ibm.wsspi.adaptable.module.Container; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.util.Util_Factory; import com.ibm.wsspi.annocache.util.Util_InternMap; import com.ibm.wsspi.annocache.util.Util_RelativePath; @@ -96,7 +97,14 @@ ClassSource_Exception wrapIntoClassSourceException( * Create a new empty aggregate class source. Assign options to the new * class source. * + * appKey will only be stored in weak references, and the cache to annotation targets will + * be lost when it is deleted. It is the responsibility of the caller to store a reference + * to appKey and delete it when the application is uninstalled. + * + * appKey can be created with new AppKey("string that is unique to app"); + * * @param appName The name of the application of the class source. + * @param appKey A key for the cache that will store annotation targets. * @param modName The name of the module of the class source. * @param modNameCategory A name used to enable multiple results for * the same module name. @@ -107,7 +115,7 @@ ClassSource_Exception wrapIntoClassSourceException( * @throws ClassSource_Exception Thrown if there was a problem creating the class source. */ ClassSource_Aggregate createAggregateClassSource( - String appName, String modName, String modNameCategory, + String appName, AppKey appKey, String modName, String modNameCategory, ClassSource_Options options) throws ClassSource_Exception; ClassSource_MappedSimple createSimpleClassSource( @@ -162,7 +170,7 @@ ClassSource_ClassLoader createClassLoaderClassSource( ClassSource_Aggregate createAggregateClassSource( Util_InternMap internMap, - String appName, String modName, String modNameCategory, + String appName, AppKey appKey, String modName, String modNameCategory, ClassSource_Options options) throws ClassSource_Exception; // diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java index f678719506f1..233ab05a1619 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java @@ -43,6 +43,7 @@ import com.ibm.wsspi.anno.classsource.ClassSource_Aggregate.ScanPolicy; import com.ibm.wsspi.anno.classsource.ClassSource_ScanCounts; import com.ibm.wsspi.anno.classsource.ClassSource_ScanCounts.ResultField; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; import com.ibm.wsspi.annocache.classsource.ClassSource_Factory; import com.ibm.wsspi.annocache.classsource.ClassSource_Streamer; @@ -66,17 +67,18 @@ public class InfoStore_Internals_Test { protected static ClassSourceImpl_Aggregate rootClassSource; protected static InfoStoreImpl infoStore; + + private static String APP_NAME = "TestEar"; + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(APP_NAME); @BeforeClass public static void setup() throws ClassSource_Exception, InfoStoreException { UtilImpl_Factory utilImplFactory = new UtilImpl_Factory(); ClassSourceImpl_Factory factory = new ClassSourceImpl_Factory(utilImplFactory); - - Properties props = System.getProperties(); - props.setProperty("running.unit.test", "true"); ClassSourceImpl_Aggregate useRootClassSource = - factory.createAggregateClassSource("TestEar", "TestMod", ClassSource_Factory.UNSET_CATEGORY_NAME, factory.createOptions() ); + factory.createAggregateClassSource(APP_NAME, appKey, "TestMod", ClassSource_Factory.UNSET_CATEGORY_NAME, factory.createOptions() ); ClassSourceImpl_MappedDirectory dirClassSource = factory.createDirectoryClassSource( diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java index 1dba39c07ad6..4d51b8ce7b34 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java @@ -31,6 +31,7 @@ import com.ibm.ws.annocache.info.internal.InfoStoreImpl; import com.ibm.ws.annocache.test.utils.TestLocalization; import com.ibm.ws.annocache.util.internal.UtilImpl_Factory; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; import com.ibm.wsspi.annocache.classsource.ClassSource_ClassLoader; import com.ibm.wsspi.annocache.classsource.ClassSource_Factory; @@ -46,6 +47,10 @@ // The subclass API is to implement test methods. public abstract class InfoStore_TestBase { + + //store a reference here so the weak reference isn't garbage collected during the test's lifetime. + private static final String APP_NAME = "AppName"; + private static AppKey appKey = null; protected SharedOutputManager outputMgr = SharedOutputManager.getInstance().trace("*=all").logTo(TestLocalization.LOGS_RELATIVE_PATH + getClass().getSimpleName()); @@ -103,10 +108,12 @@ protected static ClassSourceImpl_Aggregate createClassSource() throws Exception Properties props = System.getProperties(); props.setProperty("running.unit.test", "true"); + + appKey = new AppKey(APP_NAME); ClassSourceImpl_Aggregate useRootClassSource = factory.createAggregateClassSource( - "AppName", "ModName", ClassSource_Factory.UNSET_CATEGORY_NAME, + APP_NAME, appKey, "ModName", ClassSource_Factory.UNSET_CATEGORY_NAME, factory.createOptions() ); addComponentClassSources(useRootClassSource); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_SimpleSource_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_SimpleSource_Test.java index 3b2158b17fa9..3637a6c7f962 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_SimpleSource_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_SimpleSource_Test.java @@ -22,22 +22,25 @@ import org.junit.Test; -import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; - import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Factory; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_MappedSimple; +import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Options; import com.ibm.ws.annocache.test.scan.TestOptions_SuiteCase; import com.ibm.ws.annocache.test.scan.Test_Base; import com.ibm.ws.annocache.test.utils.TestLocalization; -import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Options; +import com.ibm.wsspi.anno.service.AppKey; +import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; public class LoginMethod_StaticAnnotationMixed_war_SimpleSource_Test extends Test_Base { public static final String EAR_NAME = LoginMethod_ear_Data.EAR_NAME; public static final String EAR_SIMPLE_NAME = LoginMethod_ear_Data.EAR_SIMPLE_NAME; public static final String WAR_NAME = LoginMethod_ear_Data.WAR_NAME_STATIC_ANNOTATION_MIXED; - public static final String WAR_SIMPLE_NAME = LoginMethod_ear_Data.WAR_SIMPLE_NAME_STATIC_ANNOTATION_MIXED; + public static final String WAR_SIMPLE_NAME = LoginMethod_ear_Data.WAR_SIMPLE_NAME_STATIC_ANNOTATION_MIXED; + + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(EAR_SIMPLE_NAME); @Override public ClassSourceImpl_Aggregate createClassSource( @@ -47,7 +50,7 @@ public ClassSourceImpl_Aggregate createClassSource( String warPath = TestLocalization.putIntoData(EAR_NAME + '/', WAR_NAME + '/'); ClassSourceImpl_Aggregate rootClassSource = - factory.createAggregateClassSource(EAR_SIMPLE_NAME, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); + factory.createAggregateClassSource(EAR_SIMPLE_NAME, appKey, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); final String warClassesPath = TestLocalization.putInto(warPath, "WEB-INF/classes"); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_Test.java index 486449534b56..6f91b460161b 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationMixed_war_Test.java @@ -15,6 +15,7 @@ import org.junit.Test; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; @@ -30,6 +31,9 @@ public class LoginMethod_StaticAnnotationMixed_war_Test extends Test_Base { public static final String WAR_NAME = LoginMethod_ear_Data.WAR_NAME_STATIC_ANNOTATION_MIXED; public static final String WAR_SIMPLE_NAME = LoginMethod_ear_Data.WAR_SIMPLE_NAME_STATIC_ANNOTATION_MIXED; + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(EAR_SIMPLE_NAME); + @Override public ClassSourceImpl_Aggregate createClassSource( ClassSourceImpl_Factory factory, @@ -38,7 +42,7 @@ public ClassSourceImpl_Aggregate createClassSource( String warPath = TestLocalization.putIntoData(EAR_NAME + '/', WAR_NAME) + '/'; ClassSourceImpl_Aggregate rootClassSource = - factory.createAggregateClassSource(EAR_SIMPLE_NAME, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); + factory.createAggregateClassSource(EAR_SIMPLE_NAME, appKey, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); addClassesDirectoryClassSource(rootClassSource, warPath); addClassLoaderClassSource(rootClassSource); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationPure_war_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationPure_war_Test.java index c033e5a05a3b..8023df2524bf 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationPure_war_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationPure_war_Test.java @@ -15,6 +15,7 @@ import org.junit.Test; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Factory; @@ -29,6 +30,9 @@ public class LoginMethod_StaticAnnotationPure_war_Test extends Test_Base { public static final String WAR_NAME = LoginMethod_ear_Data.WAR_NAME_STATIC_ANNOTATION_PURE; public static final String WAR_SIMPLE_NAME = LoginMethod_ear_Data.WAR_SIMPLE_NAME_STATIC_ANNOTATION_PURE; + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(EAR_SIMPLE_NAME); + @Override public ClassSourceImpl_Aggregate createClassSource( ClassSourceImpl_Factory factory, @@ -37,7 +41,7 @@ public ClassSourceImpl_Aggregate createClassSource( String warPath = TestLocalization.putIntoData(EAR_NAME + '/', WAR_NAME) + '/'; ClassSourceImpl_Aggregate rootClassSource = - factory.createAggregateClassSource(EAR_SIMPLE_NAME, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); + factory.createAggregateClassSource(EAR_SIMPLE_NAME, appKey, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); addClassesDirectoryClassSource(rootClassSource, warPath); addClassLoaderClassSource(rootClassSource); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationWebXML_war_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationWebXML_war_Test.java index ba1470cabeb9..91f7c5eee58a 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationWebXML_war_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/LoginMethod_StaticAnnotationWebXML_war_Test.java @@ -15,6 +15,7 @@ import org.junit.Test; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Factory; @@ -29,6 +30,9 @@ public class LoginMethod_StaticAnnotationWebXML_war_Test extends Test_Base { public static final String WAR_NAME = LoginMethod_ear_Data.WAR_NAME_STATIC_ANNOTATION_WEB_XML; public static final String WAR_SIMPLE_NAME = LoginMethod_ear_Data.WAR_SIMPLE_NAME_STATIC_ANNOTATION_WEB_XML; + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(EAR_SIMPLE_NAME); + @Override public ClassSourceImpl_Aggregate createClassSource( ClassSourceImpl_Factory factory, @@ -37,7 +41,7 @@ public ClassSourceImpl_Aggregate createClassSource( String warPath = TestLocalization.putIntoData(EAR_NAME + '/', WAR_NAME) + '/'; ClassSourceImpl_Aggregate rootClassSource = - factory.createAggregateClassSource(EAR_SIMPLE_NAME, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); + factory.createAggregateClassSource(EAR_SIMPLE_NAME, appKey, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); addClassesDirectoryClassSource(rootClassSource, warPath); addClassLoaderClassSource(rootClassSource); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsoluteNoOthers_war_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsoluteNoOthers_war_Test.java index 8ecf9a25e8f3..5d79f94df1dd 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsoluteNoOthers_war_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsoluteNoOthers_war_Test.java @@ -16,6 +16,7 @@ import org.junit.Test; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate.ScanPolicy; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Factory; @@ -31,6 +32,9 @@ public class SCITest_SCIAbsoluteNoOthers_war_Test extends Test_Base { public static final String WAR_NAME = SCITest_Data.WAR_NAME_ABSOLUTE_NO_OTHERS; public static final String WAR_SIMPLE_NAME = SCITest_Data.WAR_SIMPLE_NAME_ABSOLUTE_NO_OTHERS; + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(EAR_SIMPLE_NAME); + @Override public ClassSourceImpl_Aggregate createClassSource( ClassSourceImpl_Factory factory, @@ -39,7 +43,7 @@ public ClassSourceImpl_Aggregate createClassSource( String warPath = TestLocalization.putIntoData(EAR_NAME + '/', WAR_NAME) + '/'; ClassSourceImpl_Aggregate rootClassSource = - factory.createAggregateClassSource(EAR_SIMPLE_NAME, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); + factory.createAggregateClassSource(EAR_SIMPLE_NAME, appKey, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); addClassesDirectoryClassSource(rootClassSource, warPath); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsolute_war_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsolute_war_Test.java index 5719a8616404..ffd16484dcbe 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsolute_war_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/scan/samples/SCITest_SCIAbsolute_war_Test.java @@ -16,6 +16,7 @@ import org.junit.Test; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate.ScanPolicy; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Exception; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Aggregate; import com.ibm.ws.annocache.classsource.internal.ClassSourceImpl_Factory; @@ -30,6 +31,9 @@ public class SCITest_SCIAbsolute_war_Test extends Test_Base { public static final String WAR_NAME = SCITest_Data.WAR_NAME_ABSOLUTE; public static final String WAR_SIMPLE_NAME = SCITest_Data.WAR_SIMPLE_NAME_ABSOLUTE; + //Store a reference so WeakReferences won't be garbage collected during a test + private static AppKey appKey = new AppKey(EAR_SIMPLE_NAME); + @Override public ClassSourceImpl_Aggregate createClassSource( ClassSourceImpl_Factory factory, @@ -38,7 +42,7 @@ public ClassSourceImpl_Aggregate createClassSource( String warPath = TestLocalization.putIntoData(EAR_NAME + '/', WAR_NAME) + '/'; ClassSourceImpl_Aggregate rootClassSource = - factory.createAggregateClassSource(EAR_SIMPLE_NAME, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); + factory.createAggregateClassSource(EAR_SIMPLE_NAME, appKey, WAR_SIMPLE_NAME, JAVAEE_MOD_CATEGORY_NAME, options); addClassesDirectoryClassSource(rootClassSource, warPath); diff --git a/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationService_KeyService.java b/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationService_KeyService.java new file mode 100644 index 000000000000..68fe200b3a01 --- /dev/null +++ b/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationService_KeyService.java @@ -0,0 +1,20 @@ +package com.ibm.ws.container.service.annocache.internal; + +import com.ibm.wsspi.anno.service.AppKey; + +/** + * This service provides keys with a 1:1 mapping to each application installed. + * These keys can be used in a WeakHashMap to ensure the value is garbage collected + * when the application shuts down + */ +public interface AnnotationService_KeyService { + + /** + * Gets an AppKey for a given application + * + * @param appName the name of the application, this must be the deploymentName from com.ibm.ws.container.service.app.deploy.ApplicationInfo + * @return An AppKey for the given appName + */ + public AppKey getKeyForApp(String appName); + +} \ No newline at end of file diff --git a/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationsImpl.java b/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationsImpl.java index 949315265573..6fc24898d16a 100644 --- a/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationsImpl.java +++ b/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/AnnotationsImpl.java @@ -24,9 +24,11 @@ import com.ibm.websphere.ras.annotation.Trivial; import com.ibm.ws.container.service.annocache.Annotations; import com.ibm.ws.container.service.annocache.SpecificAnnotations; +import com.ibm.ws.kernel.service.util.ServiceCaller; import com.ibm.wsspi.adaptable.module.Container; import com.ibm.wsspi.adaptable.module.Entry; import com.ibm.wsspi.adaptable.module.UnableToAdaptException; +import com.ibm.wsspi.anno.service.AppKey; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate; import com.ibm.wsspi.annocache.classsource.ClassSource_Aggregate.ScanPolicy; import com.ibm.wsspi.annocache.classsource.ClassSource_ClassLoader; @@ -53,6 +55,8 @@ public abstract class AnnotationsImpl implements Annotations { public static final TraceComponent tc = Tr.register(AnnotationsImpl.class); // private static final String CLASS_NAME = AnnotationsImpl.class.getSimpleName(); + private static final ServiceCaller keyServiceServiceCaller = new ServiceCaller(AnnotationsImpl.class, AnnotationService_KeyService.class); + private static final String JAVAX_RESOURCE = "javax.annotation.Resource"; private static final String JAVAX_RESOURCES = "javax.annotation.Resources"; private static final String JAVAX_POST_CONSTRUCT = "javax.annotation.PostConstruct"; @@ -84,8 +88,8 @@ public PathData(String path, int spans) { } public PathData( - String path, int spans, - int spansBelowParent, int spansAboveParent) { + String path, int spans, + int spansBelowParent, int spansAboveParent) { this.path = path; this.spans = spans; @@ -96,7 +100,7 @@ public PathData( public static ArtifactContainer getRootOfRoots(ArtifactContainer container) { ArtifactEntry entry; - while ( (entry = container.getRoot().getEntryInEnclosingContainer()) != null ) { + while ((entry = container.getRoot().getEntryInEnclosingContainer()) != null) { container = entry.getEnclosingContainer(); } return container; @@ -109,39 +113,38 @@ public static ArtifactContainer getRootOfRoots(ArtifactContainer container) { * a specified parent container. * * @param parentContainer A parent container. - * @param container The container for which to obtain the full path. + * @param container The container for which to obtain the full path. * * @return Path data for the container. * * @throws UnableToAdaptException Thrown if traversal from the container - * to its parents fails. + * to its parents fails. */ public static PathData getPathData( - Container parentContainer, Container container) - throws UnableToAdaptException { + Container parentContainer, Container container) throws UnableToAdaptException { StringBuilder pathBuilder = new StringBuilder(); int spans = 0; - boolean foundParent = ( container == parentContainer ); + boolean foundParent = (container == parentContainer); int spansBelow = 0; int spansAbove = 0; Entry entry; - while ( (entry = container.adapt(Entry.class)) != null ) { // throws UnableToAdaptException + while ((entry = container.adapt(Entry.class)) != null) { // throws UnableToAdaptException // Each step upwards adds to the count of spans. spans++; // Acquire the next path-to-root. - pathBuilder.insert(0, entry.getPath() ); + pathBuilder.insert(0, entry.getPath()); container = entry.getRoot(); // Each step upwards adds to one of the span counts. // If the parent hasn't been found, the span is below the // parent. Otherwise, the span is above the parent. - if ( !foundParent ) { + if (!foundParent) { spansBelow++; } else { spansAbove++; @@ -152,14 +155,14 @@ public static PathData getPathData( // span counts, since the current traversal was used // to reach upwards towards the next parent. - if ( !foundParent ) { - foundParent = ( container == parentContainer ); + if (!foundParent) { + foundParent = (container == parentContainer); } } String path = pathBuilder.toString(); - if ( foundParent ) { + if (foundParent) { return new PathData(path, spans, spansBelow, spansAbove); } else { return new PathData(path, spans); @@ -167,16 +170,16 @@ public static PathData getPathData( } public static String getPath(Container container) throws UnableToAdaptException { - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { Tr.debug(tc, "getPath Initial [ " + container + " ]"); } StringBuilder pathBuilder = new StringBuilder(); Entry entry; - while ( (entry = container.adapt(Entry.class)) != null ) { // throws UnableToAdaptException - pathBuilder.insert(0, entry.getPath() ); + while ((entry = container.adapt(Entry.class)) != null) { // throws UnableToAdaptException + pathBuilder.insert(0, entry.getPath()); container = entry.getRoot(); - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { Tr.debug(tc, "getPath Next [ " + container + " ]"); } } @@ -189,7 +192,7 @@ protected String getContainerPath(Container targetContainer) { String useModName = getModName(); Container modContainer = rootAdaptableContainer; - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { Tr.debug(tc, "AppName [ " + useAppName + " ]"); Tr.debug(tc, "Mod Name [ " + useModName + " ]"); Tr.debug(tc, "Module Container [ " + modContainer + " ]"); @@ -199,54 +202,54 @@ protected String getContainerPath(Container targetContainer) { String targetPath; try { targetPath = getPath(targetContainer); - } catch ( UnableToAdaptException e ) { + } catch (UnableToAdaptException e) { return null; // FFDC } - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { Tr.debug(tc, "Target Path [ " + targetPath + " ]"); } ArtifactContainer modDelegate; try { modDelegate = modContainer.adapt(ArtifactContainer.class); - } catch ( UnableToAdaptException e ) { + } catch (UnableToAdaptException e) { return null; // FFDC } - if ( tc.isDebugEnabled() ) { - Tr.debug(tc, "Module Delegate [ " + modDelegate + " ]"); + if (tc.isDebugEnabled()) { + Tr.debug(tc, "Module Delegate [ " + modDelegate + " ]"); } ArtifactContainer targetDelegate; try { targetDelegate = targetContainer.adapt(ArtifactContainer.class); - } catch ( UnableToAdaptException e ) { + } catch (UnableToAdaptException e) { return null; } - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { Tr.debug(tc, "Target Delegate [ " + targetDelegate + " ]"); } ArtifactContainer rootOfRootsModDelegate = getRootOfRoots(modDelegate); ArtifactContainer rootOfRootsTargetDelegate = getRootOfRoots(targetDelegate); - if ( tc.isDebugEnabled() ) { - Tr.debug(tc, "Module Delegate Root-of-roots [ " + rootOfRootsModDelegate + " ]"); - Tr.debug(tc, "Target Delegate Root-of-roots[ " + rootOfRootsTargetDelegate + " ]"); + if (tc.isDebugEnabled()) { + Tr.debug(tc, "Module Delegate Root-of-roots [ " + rootOfRootsModDelegate + " ]"); + Tr.debug(tc, "Target Delegate Root-of-roots[ " + rootOfRootsTargetDelegate + " ]"); } String targetPathCase; - if ( targetPath.isEmpty() || - (modDelegate == rootOfRootsModDelegate) || - (rootOfRootsModDelegate == null) || (rootOfRootsTargetDelegate == null) || - (rootOfRootsModDelegate != rootOfRootsTargetDelegate) ) { + if (targetPath.isEmpty() || + (modDelegate == rootOfRootsModDelegate) || + (rootOfRootsModDelegate == null) || (rootOfRootsTargetDelegate == null) || + (rootOfRootsModDelegate != rootOfRootsTargetDelegate)) { - if ( (useModName == null) || useModName.isEmpty() ) { - if ( (useAppName == null) || useAppName.isEmpty() ) { + if ((useModName == null) || useModName.isEmpty()) { + if ((useAppName == null) || useAppName.isEmpty()) { Tr.warning(tc, "Unable to obtain path for container [ " + targetContainer + " ] relative to [ " + modContainer + " ]"); return null; } else { - if ( targetPath.isEmpty() ) { + if (targetPath.isEmpty()) { targetPath = useAppName; targetPathCase = "App name replaces empty target path"; } else { @@ -256,7 +259,7 @@ protected String getContainerPath(Container targetContainer) { } } else { - if ( targetPath.isEmpty() ) { + if (targetPath.isEmpty()) { targetPath = useModName; targetPathCase = "Mod name replaces empty target path"; } else { @@ -266,14 +269,14 @@ protected String getContainerPath(Container targetContainer) { } } - } else { + } else { targetPathCase = "Full local path"; } if (tc.isDebugEnabled()) { String message = getClass().getSimpleName() + ".getContainerPath:" + - " Container [ " + targetContainer + " ]" + - " Path [ " + targetPath + " ]: " + targetPathCase; + " Container [ " + targetContainer + " ]" + + " Path [ " + targetPath + " ]: " + targetPathCase; Tr.debug(tc, message); } @@ -284,24 +287,24 @@ protected String getContainerPath(Container targetContainer) { @SuppressWarnings("unchecked") protected static T cacheGet( - OverlayContainer container, - String targetPath, Class targetClass) { + OverlayContainer container, + String targetPath, Class targetClass) { Object retrievedInfo = container.getFromNonPersistentCache(targetPath, targetClass); return (T) retrievedInfo; } protected static void cachePut( - OverlayContainer container, - String targetPath, Class targetClass, - T targetObject) { + OverlayContainer container, + String targetPath, Class targetClass, + T targetObject) { container.addToNonPersistentCache(targetPath, targetClass, targetObject); } protected static void cacheRemove( - OverlayContainer container, - String targetPath, Class targetClass) { + OverlayContainer container, + String targetPath, Class targetClass) { container.removeFromNonPersistentCache(targetPath, targetClass); } @@ -314,26 +317,26 @@ protected static void cacheRemove( * The adapter provides access to service entities, most importantly, the * annotation factories. * - * @param annotationsAdapter The adapter which is creating the annotations data. - * @param rootContainer The root adaptable container. Currently always the same - * as 'rootAdaptableContainer'. - * @param rootOverlayContainer The root overlay container. - * @param rootDelegateContainer The delegate of the root adaptable container. - * @param rootAdaptableContainer The root adaptable container. Currently, always - * the same as 'rootContainer'. - * @param appName The name of the enclosing application. Null if there is no enclosing - * application. - * @param isUnnamedMod Set that the module is unnamed. This prevents default module - * naming from occurring. - * @param modName The name of the enclosing module. Null if there is no enclosing module. - * @param modCatName A category name for the module. Used to enable multiple results for - * the same module. + * @param annotationsAdapter The adapter which is creating the annotations data. + * @param rootContainer The root adaptable container. Currently always the same + * as 'rootAdaptableContainer'. + * @param rootOverlayContainer The root overlay container. + * @param rootDelegateContainer The delegate of the root adaptable container. + * @param rootAdaptableContainer The root adaptable container. Currently, always + * the same as 'rootContainer'. + * @param appName The name of the enclosing application. Null if there is no enclosing + * application. + * @param isUnnamedMod Set that the module is unnamed. This prevents default module + * naming from occurring. + * @param modName The name of the enclosing module. Null if there is no enclosing module. + * @param modCatName A category name for the module. Used to enable multiple results for + * the same module. */ public AnnotationsImpl( - AnnotationsAdapterImpl annotationsAdapter, - Container rootContainer, OverlayContainer rootOverlayContainer, - ArtifactContainer rootDelegateContainer, Container rootAdaptableContainer, - String appName, boolean isUnnamedMod, String modName, String modCatName) { + AnnotationsAdapterImpl annotationsAdapter, + Container rootContainer, OverlayContainer rootOverlayContainer, + ArtifactContainer rootDelegateContainer, Container rootAdaptableContainer, + String appName, boolean isUnnamedMod, String modName, String modCatName) { // (new Throwable("Annotations (cache)")).printStackTrace(System.out); @@ -361,10 +364,10 @@ public AnnotationsImpl( // - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { String prefix = getClass().getSimpleName() + ".: "; Tr.debug(tc, prefix + "Root container [ " + rootContainer + " ]"); - for ( URL url : rootContainer.getURLs() ) { + for (URL url : rootContainer.getURLs()) { Tr.debug(tc, prefix + " URL [ " + url + " ]"); } Tr.debug(tc, prefix + "Application [ " + appName + " ]"); @@ -381,24 +384,24 @@ public AnnotationCacheService_Service getAnnoCacheService() { try { return annotationsAdapter.getAnnoCacheService(); // throws UnableToAdaptException - } catch ( UnableToAdaptException e ) { + } catch (UnableToAdaptException e) { return null; // FFDC } } public ClassSource_Factory getClassSourceFactory() { AnnotationCacheService_Service useService = getAnnoCacheService(); - return ( (useService == null) ? null : useService.getClassSourceFactory() ); + return ((useService == null) ? null : useService.getClassSourceFactory()); } public AnnotationTargets_Factory getTargetsFactory() { AnnotationCacheService_Service useService = getAnnoCacheService(); - return ( (useService == null) ? null : useService.getAnnotationTargetsFactory() ); + return ((useService == null) ? null : useService.getAnnotationTargetsFactory()); } public InfoStoreFactory getInfoStoreFactory() { AnnotationCacheService_Service useService = getAnnoCacheService(); - return ( (useService == null) ? null : useService.getInfoStoreFactory() ); + return ((useService == null) ? null : useService.getInfoStoreFactory()); } // @@ -427,11 +430,11 @@ protected T cacheGet(Class targetClass) { } protected void cachePut(Class targetClass, T targetObject) { - cachePut( getRootOverlayContainer(), getContainerPath(), targetClass, targetObject); + cachePut(getRootOverlayContainer(), getContainerPath(), targetClass, targetObject); } protected void cacheRemove(Class targetClass) { - cacheRemove( getRootOverlayContainer(), getContainerPath(), targetClass); + cacheRemove(getRootOverlayContainer(), getContainerPath(), targetClass); } // @@ -448,7 +451,7 @@ public String getContainerName() { return getContainer().getName(); } - @Override + @Override public String getContainerPath() { return getContainer().getPath(); } @@ -469,13 +472,13 @@ public void setUseJandex(boolean useJandex) { protected ClassSource_Options createOptions() { ClassSource_Factory classSourceFactory = getClassSourceFactory(); - if ( classSourceFactory == null ) { + if (classSourceFactory == null) { return null; } ClassSource_Options options = classSourceFactory.createOptions(); - if ( !options.getIsSetUseJandex() ) { - options.setUseJandex( getUseJandex() ); + if (!options.getIsSetUseJandex()) { + options.setUseJandex(getUseJandex()); } else { // TODO: *Maybe*, NLS enable this. // The override is an unpublished system property. This message should @@ -510,22 +513,22 @@ public void setIsUnnamedMod(boolean isUnnamedMod) { this.isUnnamedMod = isUnnamedMod; } - @Override - public boolean getIsUnnamedMod() { + @Override + public boolean getIsUnnamedMod() { return isUnnamedMod; } protected void forceModName() throws UnableToAdaptException { - if ( getIsUnnamedMod() ) { + if (getIsUnnamedMod()) { return; } - if ( (modName == null) || modName.isEmpty() ) { + if ((modName == null) || modName.isEmpty()) { String modNameCase; - String useModName = getPath( getContainer() ); // 'getPath' throws UnableToAdaptException - if ( (useModName == null) || useModName.isEmpty() ) { + String useModName = getPath(getContainer()); // 'getPath' throws UnableToAdaptException + if ((useModName == null) || useModName.isEmpty()) { useModName = getAppName(); - if ( (useModName == null) || useModName.isEmpty() ) { + if ((useModName == null) || useModName.isEmpty()) { useModName = null; modNameCase = "unavailable"; return; @@ -537,11 +540,11 @@ protected void forceModName() throws UnableToAdaptException { } modName = useModName; - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { String message = getClass().getSimpleName() + ".forceModName:" + - " App [ " + getAppName() + " ]" + - " Container [ " + getContainer() + " ]" + - " Mod [ " + modName + " ] (" + modNameCase + ")"; + " App [ " + getAppName() + " ]" + + " Container [ " + getContainer() + " ]" + + " Mod [ " + modName + " ] (" + modNameCase + ")"; Tr.debug(tc, message); } } @@ -578,6 +581,7 @@ public void setIsLightweight(boolean isLightweight) { public class ClassSourceLock { // EMPTY } + private final ClassSourceLock classSourceLock = new ClassSourceLock(); protected ClassLoader classLoader; @@ -592,8 +596,8 @@ protected boolean addContainerClassSource(String path, Container container, Stri ClassSource_MappedContainer containerClassSource; try { containerClassSource = getClassSourceFactory().createContainerClassSource( - rootClassSource, path, container, entryPrefix); // throws ClassSource_Exception - } catch ( ClassSource_Exception e ) { + rootClassSource, path, container, entryPrefix); // throws ClassSource_Exception + } catch (ClassSource_Exception e) { return false; // FFDC } rootClassSource.addClassSource(containerClassSource); @@ -608,8 +612,8 @@ protected boolean addContainerClassSource(String path, Container container, Stri ClassSource_MappedContainer containerClassSource; try { containerClassSource = getClassSourceFactory().createContainerClassSource( - rootClassSource, path, container, entryPrefix); // throws ClassSource_Exception - } catch ( ClassSource_Exception e ) { + rootClassSource, path, container, entryPrefix); // throws ClassSource_Exception + } catch (ClassSource_Exception e) { return false; // FFDC } rootClassSource.addClassSource(containerClassSource, scanPolicy); @@ -618,16 +622,16 @@ protected boolean addContainerClassSource(String path, Container container, Stri @Override public ClassLoader getClassLoader() { - synchronized ( classSourceLock ) { + synchronized (classSourceLock) { return classLoader; } } @Override public void setClassLoader(ClassLoader classLoader) { - synchronized ( classSourceLock ) { - if ( this.classLoader != null ) { - if ( this.classLoader != classLoader ) { + synchronized (classSourceLock) { + if (this.classLoader != null) { + if (this.classLoader != classLoader) { throw new IllegalArgumentException("Duplicate class loader [ " + classLoader + " ]; previous [ " + this.classLoader + " ]"); } else { return; // Nothing to do. @@ -643,8 +647,8 @@ public void setClassLoader(ClassLoader classLoader) { @Override public ClassSource_Aggregate releaseClassSource() { - synchronized ( classSourceLock ) { - if ( rootClassSource == null ) { + synchronized (classSourceLock) { + if (rootClassSource == null) { return null; } @@ -657,15 +661,14 @@ public ClassSource_Aggregate releaseClassSource() { @Override public ClassSource_Aggregate getClassSource() { - synchronized( classSourceLock ) { - if ( rootClassSource == null ) { + synchronized (classSourceLock) { + if (rootClassSource == null) { rootClassSource = createRootClassSource(); - if ( rootClassSource == null ) { - String message = - "Null class source created for " + - " app [ " + appName + " ]" + - " module [ " + modName + " ]" + - " module category [ " + modCatName + " ]"; + if (rootClassSource == null) { + String message = "Null class source created for " + + " app [ " + appName + " ]" + + " module [ " + modName + " ]" + + " module category [ " + modCatName + " ]"; Tr.warning(tc, getClass().getName() + ": " + message); } addInternalToClassSource(); @@ -677,13 +680,13 @@ public ClassSource_Aggregate getClassSource() { protected ClassSource_Aggregate createRootClassSource() { ClassSource_Factory classSourceFactory = getClassSourceFactory(); - if ( classSourceFactory == null ) { + if (classSourceFactory == null) { return null; } try { forceModName(); // throws UnableToAdaptException - } catch ( UnableToAdaptException e ) { + } catch (UnableToAdaptException e) { // FFDC return null; } @@ -694,24 +697,25 @@ protected ClassSource_Aggregate createRootClassSource() { ClassSource_Options options = createOptions(); - if ( tc.isDebugEnabled() ) { + if (tc.isDebugEnabled()) { String prefix = getClass().getSimpleName() + ".createRootClassSource:"; String message1 = prefix + - " Class source " + - " app [ " + useAppName + " ]" + - " module [ " + useModName + " ]" + - " module category [ " + useModCatName + " ]"; + " Class source " + + " app [ " + useAppName + " ]" + + " module [ " + useModName + " ]" + + " module category [ " + useModCatName + " ]"; String message2 = prefix + - " Scan threads [ " + options.getScanThreads() + " ]"; + " Scan threads [ " + options.getScanThreads() + " ]"; Tr.debug(tc, message1); Tr.debug(tc, message2); } try { + AppKey appKey = keyServiceServiceCaller.run((AnnotationService_KeyService ks) -> ks.getKeyForApp(useAppName)).get(); return classSourceFactory.createAggregateClassSource( - useAppName, useModName, useModCatName, - options); // throws ClassSource_Exception - } catch ( ClassSource_Exception e ) { + useAppName, appKey, useModName, useModCatName, + options); // throws ClassSource_Exception + } catch (ClassSource_Exception e) { return null; // FFDC } } @@ -719,22 +723,22 @@ protected ClassSource_Aggregate createRootClassSource() { protected abstract void addInternalToClassSource(); protected void addExternalToClassSource() { - if ( rootClassSource == null ) { + if (rootClassSource == null) { return; // Nothing yet to do. - } else if ( classLoader == null ) { + } else if (classLoader == null) { return; // Nothing yet to do. } ClassSource_Factory classSourceFactory = getClassSourceFactory(); - if ( classSourceFactory == null ) { + if (classSourceFactory == null) { return; } ClassSource_ClassLoader classLoaderClassSource; try { classLoaderClassSource = classSourceFactory.createClassLoaderClassSource( - rootClassSource, "classloader", classLoader); // throws ClassSource_Exception - } catch ( ClassSource_Exception e ) { + rootClassSource, "classloader", classLoader); // throws ClassSource_Exception + } catch (ClassSource_Exception e) { return; // FFDC } rootClassSource.addClassLoaderClassSource(classLoaderClassSource); @@ -796,6 +800,7 @@ private void checkForWrongPackageCommonAnnotations(AnnotationTargets_Targets tar public class TargetsLock { // EMPTY } + private final TargetsLock targetsLock = new TargetsLock(); private boolean isSetTargets; @@ -804,8 +809,8 @@ public class TargetsLock { @Override public AnnotationTargets_Targets getTargets() { boolean checkWrongPackage = false; - synchronized( targetsLock ) { - if ( !isSetTargets ) { + synchronized (targetsLock) { + if (!isSetTargets) { isSetTargets = true; checkWrongPackage = true; annotationTargets = createTargets(); @@ -830,8 +835,8 @@ public AnnotationTargets_Targets getAnnotationTargets() { @Override public AnnotationTargets_Targets releaseTargets() { - synchronized ( targetsLock ) { - if ( !isSetTargets ) { + synchronized (targetsLock) { + if (!isSetTargets) { return null; } @@ -848,40 +853,37 @@ public AnnotationTargets_Targets releaseTargets() { protected AnnotationTargets_Targets createTargets() { ClassSource_Aggregate useClassSource = getClassSource(); - if ( useClassSource == null ) { - String message = - "Null class source creating targets for " + - " app [ " + appName + " ]" + - " module [ " + modName + " ]" + - " module category [ " + modCatName + " ]"; + if (useClassSource == null) { + String message = "Null class source creating targets for " + + " app [ " + appName + " ]" + + " module [ " + modName + " ]" + + " module category [ " + modCatName + " ]"; Tr.warning(tc, getClass().getName() + ": " + message); return null; } AnnotationTargets_Factory targetsFactory = getTargetsFactory(); - if ( targetsFactory == null ) { - String message = - "Null factory creating targets for " + - " app [ " + appName + " ]" + - " module [ " + modName + " ]" + - " module category [ " + modCatName + " ]"; + if (targetsFactory == null) { + String message = "Null factory creating targets for " + + " app [ " + appName + " ]" + + " module [ " + modName + " ]" + + " module category [ " + modCatName + " ]"; Tr.warning(tc, getClass().getName() + ": " + message); return null; } - if ( classLoader == null ) { - String message = - "Null class loader creating targets for " + - " app [ " + appName + " ]" + - " module [ " + modName + " ]" + - " module category [ " + modCatName + " ]"; + if (classLoader == null) { + String message = "Null class loader creating targets for " + + " app [ " + appName + " ]" + + " module [ " + modName + " ]" + + " module category [ " + modCatName + " ]"; Tr.debug(tc, getClass().getName() + ": " + message); } AnnotationTargets_Targets useTargets; try { - useTargets = targetsFactory.createTargets( getIsLightweight() ); // throws AnnotationTargets_Exception - } catch ( AnnotationTargets_Exception e ) { + useTargets = targetsFactory.createTargets(getIsLightweight()); // throws AnnotationTargets_Exception + } catch (AnnotationTargets_Exception e) { return null; // FFDC } @@ -900,6 +902,7 @@ protected AnnotationTargets_Targets createTargets() { public class InfoStoreLock { // EMPTY } + private final InfoStoreLock infoStoreLock = new InfoStoreLock(); private boolean isSetInfoStore; @@ -907,8 +910,8 @@ public class InfoStoreLock { @Override public InfoStore releaseInfoStore() { - synchronized ( infoStoreLock ) { - if ( !isSetInfoStore ) { + synchronized (infoStoreLock) { + if (!isSetInfoStore) { return null; } @@ -923,9 +926,10 @@ public InfoStore releaseInfoStore() { } } + @Override public InfoStore getInfoStore() { - synchronized( infoStoreLock ) { - if ( !isSetInfoStore ) { + synchronized (infoStoreLock) { + if (!isSetInfoStore) { isSetInfoStore = true; infoStore = createInfoStore(); } @@ -936,18 +940,18 @@ public InfoStore getInfoStore() { protected InfoStore createInfoStore() { ClassSource_Aggregate useClassSource = getClassSource(); - if ( useClassSource == null ) { + if (useClassSource == null) { return null; } InfoStoreFactory infoStoreFactory = getInfoStoreFactory(); - if ( infoStoreFactory == null ) { + if (infoStoreFactory == null) { return null; } try { return infoStoreFactory.createInfoStore(useClassSource); - } catch ( InfoStoreException e ) { + } catch (InfoStoreException e) { return null; // FFDC } } @@ -957,7 +961,7 @@ protected InfoStore createInfoStore() { @Override public boolean isIncludedClass(String className) { AnnotationTargets_Targets useTargets = getTargets(); - if ( useTargets == null ) { + if (useTargets == null) { return false; } else { return useTargets.isSeedClassName(className); @@ -967,7 +971,7 @@ public boolean isIncludedClass(String className) { @Override public boolean isPartialClass(String className) { AnnotationTargets_Targets useTargets = getTargets(); - if ( useTargets == null ) { + if (useTargets == null) { return false; } else { return useTargets.isPartialClassName(className); @@ -977,7 +981,7 @@ public boolean isPartialClass(String className) { @Override public boolean isExcludedClass(String className) { AnnotationTargets_Targets useTargets = getTargets(); - if ( useTargets == null ) { + if (useTargets == null) { return false; } else { return useTargets.isExcludedClassName(className); @@ -987,7 +991,7 @@ public boolean isExcludedClass(String className) { @Override public boolean isExternalClass(String className) { AnnotationTargets_Targets useTargets = getTargets(); - if ( useTargets == null ) { + if (useTargets == null) { return false; } else { return useTargets.isExternalClassName(className); @@ -1005,7 +1009,7 @@ public ClassInfo getClassInfo(String className) { public void openInfoStore() { try { getInfoStore().open(); - } catch ( InfoStoreException e ) { + } catch (InfoStoreException e) { // FFDC } } @@ -1014,7 +1018,7 @@ public void openInfoStore() { public void closeInfoStore() { try { getInfoStore().close(); - } catch ( InfoStoreException e ) { + } catch (InfoStoreException e) { // FFDC } } @@ -1024,12 +1028,12 @@ public void closeInfoStore() { @Override public SpecificAnnotations getSpecificAnnotations(Set specificClassNames) throws UnableToAdaptException { ClassSource_Aggregate useClassSource = getClassSource(); - if ( useClassSource == null ) { + if (useClassSource == null) { return null; } AnnotationTargets_Factory useTargetsFactory = getTargetsFactory(); - if ( useTargetsFactory == null ) { + if (useTargetsFactory == null) { return null; } @@ -1038,15 +1042,15 @@ public SpecificAnnotations getSpecificAnnotations(Set specificClassNames specificTargets = useTargetsFactory.createTargets(); } catch (AnnotationTargets_Exception e) { String msg = Tr.formatMessage(tc, "failed.to.obtain.module.annotation.targets.CWWKM0473E", - "Failed to obtain annotation targets", e); + "Failed to obtain annotation targets", e); throw new UnableToAdaptException(msg); } try { specificTargets.scan(useClassSource, specificClassNames); - } catch ( AnnotationTargets_Exception e ) { + } catch (AnnotationTargets_Exception e) { String msg = Tr.formatMessage(tc, "failed.to.obtain.module.annotation.targets.CWWKM0474E", - "Failed to obtain annotation targets", specificClassNames, e); + "Failed to obtain annotation targets", specificClassNames, e); throw new UnableToAdaptException(msg); } @@ -1058,16 +1062,16 @@ public SpecificAnnotations getSpecificAnnotations(Set specificClassNames @Override public boolean hasSpecifiedAnnotations(Collection annotationClassNames) { AnnotationTargets_Targets useTargets = getTargets(); - if ( useTargets == null ) { + if (useTargets == null) { return false; } // d95160: The prior implementation obtained classes from the SEED location. // That implementation is not changed by d95160. - for ( String annotationClassName : annotationClassNames ) { + for (String annotationClassName : annotationClassNames) { Set annotatedClassNames = useTargets.getAnnotatedClasses(annotationClassName); - if ( !annotatedClassNames.isEmpty() ) { + if (!annotatedClassNames.isEmpty()) { return true; } } @@ -1077,22 +1081,22 @@ public boolean hasSpecifiedAnnotations(Collection annotationClassNames) @Override @Trivial public Set getClassesWithAnnotation(String annotationClassName) { - return getClassesWithAnnotations( Collections.singletonList(annotationClassName) ); + return getClassesWithAnnotations(Collections.singletonList(annotationClassName)); } @Override public Set getClassesWithAnnotations(Collection annotationClassNames) { AnnotationTargets_Targets useTargets = getTargets(); - if ( useTargets == null ) { + if (useTargets == null) { return Collections.emptySet(); } Set annotatedClassNames = null; - for ( String annotationClassName : annotationClassNames ) { + for (String annotationClassName : annotationClassNames) { Set nextClassNames = useTargets.getAnnotatedClasses(annotationClassName); - if ( !nextClassNames.isEmpty() ) { - if ( annotatedClassNames == null ) { + if (!nextClassNames.isEmpty()) { + if (annotatedClassNames == null) { annotatedClassNames = new HashSet(nextClassNames); } else { annotatedClassNames.addAll(nextClassNames); @@ -1100,7 +1104,7 @@ public Set getClassesWithAnnotations(Collection annotationClassN } } - if ( annotatedClassNames == null ) { + if (annotatedClassNames == null) { return Collections.emptySet(); } else { return annotatedClassNames; @@ -1114,16 +1118,15 @@ public Set getClassesWithSpecifiedInheritedAnnotations(Collection allAnnotatedClassNames = new HashSet(); - for ( String annotationClassName : annotationClassNames ) { - Set annotatedClassNames = - useTargets.getAllInheritedAnnotatedClasses(annotationClassName); + for (String annotationClassName : annotationClassNames) { + Set annotatedClassNames = useTargets.getAllInheritedAnnotatedClasses(annotationClassName); // Tr.info(tc, prefix + "Annotation [ " + annotationClassName + " ] [ " + annotatedClassNames + " ]"); allAnnotatedClassNames.addAll(annotatedClassNames); } diff --git a/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/ApplicationKeyServiceImpl.java b/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/ApplicationKeyServiceImpl.java index 728abab5e0c5..0968cef0d3f1 100644 --- a/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/ApplicationKeyServiceImpl.java +++ b/dev/com.ibm.ws.container.service/src/com/ibm/ws/container/service/annocache/internal/ApplicationKeyServiceImpl.java @@ -12,7 +12,7 @@ import com.ibm.ws.container.service.metadata.MetaDataEvent; import com.ibm.ws.container.service.metadata.MetaDataException; import com.ibm.ws.runtime.metadata.ApplicationMetaData; -import com.ibm.wsspi.anno.service.AnnotationService_KeyService; +import com.ibm.wsspi.anno.service.AppKey; @Component public class ApplicationKeyServiceImpl implements AnnotationService_KeyService, ApplicationMetaDataListener { @@ -20,13 +20,14 @@ public class ApplicationKeyServiceImpl implements AnnotationService_KeyService, static final TraceComponent tc = Tr.register(ApplicationKeyServiceImpl.class); private final boolean isDebug = TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled(); + private final AppKey nullKey = new AppKey(null); private final Map keys = new ConcurrentHashMap(); /** * {@inheritDoc} */ @Override - public AnnotationService_KeyService.AppKey getKeyForApp(String appName) { + public com.ibm.wsspi.anno.service.AppKey getKeyForApp(String appName) { // appName will come from the input to // com.ibm.ws.container.service.annocache.internal.ClassSourceImpl_Aggregate. @@ -55,7 +56,10 @@ public AnnotationService_KeyService.AppKey getKeyForApp(String appName) { Tr.debug(tc, "A key for for {0}, was not found. It will be created."); } - return keys.computeIfAbsent(appName, AnnotationService_KeyService.AppKey::new); + if (appName == null) { + return nullKey; + } + return keys.computeIfAbsent(appName, AppKey::new); } @Override