oracle / oci-java-sdk

Oracle Cloud Infrastructure SDK for Java
https://cloud.oracle.com/cloud-infrastructure
Other
192 stars 152 forks source link

Cannot redefine service '%s'. Existing: '%s', New: '%s' #564

Open gandra opened 6 months ago

gandra commented 6 months ago

I am trying to instantiate 2 SubscriptionClient one from package com.oracle.bmc.onesubscription and another one from package com.oracle.bmc.tenantmanagercontrolplane.SubscriptionClient in different places inside same springbooot app and getting error:

java.lang.IllegalArgumentException: Cannot redefine service 'SUBSCRIPTION'. Existing: 'Services.BasicService(serviceName=SUBSCRIPTION, serviceEndpointPrefix=, serviceEndpointTemplate=https://organizations.{region}.oci.{secondLevelDomain}, endpointServiceName=null)', New: 'Services.BasicService(serviceName=SUBSCRIPTION, serviceEndpointPrefix=, serviceEndpointTemplate=https://identity.{region}.oci.{secondLevelDomain}, endpointServiceName=null)'

Here is instance 1:

try(com.oracle.bmc.onesubscription.SubscriptionClient subscriptionClient = SubscriptionClient.builder().region(provider.getRegion()).build(provider))  {
   ...
   ListSubscriptionsResponse listSubscriptionsResponse = subscriptionClient.listSubscriptions(listSubscriptionsRequest);
   ...
}

instance 2:

try(com.oracle.bmc.tenantmanagercontrolplane.SubscriptionClient subscriptionClient = com.oracle.bmc.tenantmanagercontrolplane.SubscriptionClient.builder().region(provider.getRegion()).build(provider))  {
}

Here is debug screenshot with root cause:
image

com.oracle.bmc.Services has static cache:

private static final Map<String, Service> SERVICE_CACHE = new HashMap<>();

which prevents instantiating different clients with same service name ... any idea how to fix this?