java.lang.constant.ClassDesc uses String.format resulting in a ClassCircularityError. String.format() uses the default locale and may need to load providers for Locale that is not already cached.
The implementation that loads providers calls ClassDesc.nested() which intern calls String.format which needs to load a provider.
The circularity error only occurs with some other changes that change the indirectly cause the Locale to be cached.
A simple fix is to replace the call to String.format with either String concatenation or string.concat. Or to use a fixed locale like Locale.ENGLISH.
Example:
import java.text.NumberFormat;
import java.util.Locale;
public class Circ {
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH);
System.setSecurityManager(new SecurityManager());
NumberFormat nf = NumberFormat.getInstance();
}
}
Produces the stack trace:
Exception in thread "main" java.util.ServiceConfigurationError: sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:583)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:864)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1077)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:402)
at java.base/java.lang.Class.newInstance(Class.java:592)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:176)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:279)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:250)
at java.base/java.text.NumberFormat.getInstance(NumberFormat.java:951)
at java.base/java.text.NumberFormat.getInstance(NumberFormat.java:478)
at Circ.main(Circ.java:10)
Caused by: java.util.ServiceConfigurationError: sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:583)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:864)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1077)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:402)
at java.base/java.lang.Class.newInstance(Class.java:592)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:176)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:279)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:250)
at java.base/java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:178)
at java.base/java.util.Formatter.getZero(Formatter.java:2437)
at java.base/java.util.Formatter.<init>(Formatter.java:1956)
at java.base/java.util.Formatter.<init>(Formatter.java:1978)
at java.base/java.lang.String.format(String.java:2988)
at java.base/java.lang.constant.ClassDesc.nested(ClassDesc.java:204)
at java.base/java.lang.constant.ConstantDescs.<clinit>(ConstantDescs.java:121)
at java.base/java.lang.invoke.VarHandle$VarHandleDesc$Kind.<clinit>(VarHandle.java:2132)
at java.base/java.lang.invoke.VarHandle$2.<clinit>(VarHandle.java:2143)
at java.base/java.lang.invoke.VarHandle$AccessType.accessModeType(VarHandle.java:1554)
at java.base/java.lang.invoke.VarHandleReferences$FieldInstanceReadOnly.accessModeTypeUncached(VarHandleReferences.java:59)
at java.base/java.lang.invoke.VarHandle.accessModeType(VarHandle.java:1919)
at java.base/java.lang.invoke.VarHandle.getMethodHandleUncached(VarHandle.java:2020)
at java.base/java.lang.invoke.VarHandle.getMethodHandle(VarHandle.java:2015)
at java.base/java.lang.invoke.Invokers.checkVarHandleGenericType(Invokers.java:453)
at java.base/java.util.concurrent.ConcurrentSkipListMap.doPut(ConcurrentSkipListMap.java:606)
at java.base/java.util.concurrent.ConcurrentSkipListMap.merge(ConcurrentSkipListMap.java:1556)
at java.base/java.net.SocketPermissionCollection.add(SocketPermission.java:1381)
at java.base/java.security.Permissions.add(Permissions.java:132)
at java.base/sun.security.provider.PolicyFile.addPerms(PolicyFile.java:1339)
at java.base/sun.security.provider.PolicyFile.addPermissions(PolicyFile.java:1196)
at java.base/sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1140)
at java.base/sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1104)
at java.base/sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1044)
at java.base/sun.security.provider.PolicyFile.implies(PolicyFile.java:1000)
at java.base/java.security.ProtectionDomain.implies(ProtectionDomain.java:321)
at java.base/java.security.ProtectionDomain.impliesWithAltFilePerm(ProtectionDomain.java:353)
at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:450)
at java.base/java.security.AccessController.checkPermission(AccessController.java:1042)
at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:408)
at java.base/java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1324)
at java.base/java.lang.ClassLoader$1.run(ClassLoader.java:690)
at java.base/java.lang.ClassLoader$1.run(ClassLoader.java:688)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.base/java.lang.ClassLoader.checkPackageAccess(ClassLoader.java:688)
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:761)
at java.base/jdk.internal.loader.BuiltinClassLoader.lambda$findClassInModuleOrNull$2(BuiltinClassLoader.java:684)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:685)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:563)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
at java.base/java.lang.Class.forName(Class.java:493)
at java.base/java.util.ServiceLoader.lambda$loadProvider$1(ServiceLoader.java:858)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:860)
... 20 more
Caused by: java.lang.ClassCircularityError: sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:761)
at java.base/jdk.internal.loader.BuiltinClassLoader.lambda$findClassInModuleOrNull$2(BuiltinClassLoader.java:684)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:685)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:563)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
at java.base/java.lang.Class.forName(Class.java:493)
at java.base/java.util.ServiceLoader.lambda$loadProvider$1(ServiceLoader.java:858)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:860)
... 85 more
The implementation that loads providers calls ClassDesc.nested() which intern calls String.format which needs to load a provider.
The circularity error only occurs with some other changes that change the indirectly cause the Locale to be cached.
A simple fix is to replace the call to String.format with either String concatenation or string.concat. Or to use a fixed locale like Locale.ENGLISH.
Example:
import java.text.NumberFormat;
import java.util.Locale;
public class Circ {
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH);
System.setSecurityManager(new SecurityManager());
NumberFormat nf = NumberFormat.getInstance();
}
}
Produces the stack trace:
Exception in thread "main" java.util.ServiceConfigurationError: sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:583)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:864)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1077)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:402)
at java.base/java.lang.Class.newInstance(Class.java:592)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:176)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:279)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:250)
at java.base/java.text.NumberFormat.getInstance(NumberFormat.java:951)
at java.base/java.text.NumberFormat.getInstance(NumberFormat.java:478)
at Circ.main(Circ.java:10)
Caused by: java.util.ServiceConfigurationError: sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:583)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:864)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1077)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:402)
at java.base/java.lang.Class.newInstance(Class.java:592)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:176)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:279)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:250)
at java.base/java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:178)
at java.base/java.util.Formatter.getZero(Formatter.java:2437)
at java.base/java.util.Formatter.<init>(Formatter.java:1956)
at java.base/java.util.Formatter.<init>(Formatter.java:1978)
at java.base/java.lang.String.format(String.java:2988)
at java.base/java.lang.constant.ClassDesc.nested(ClassDesc.java:204)
at java.base/java.lang.constant.ConstantDescs.<clinit>(ConstantDescs.java:121)
at java.base/java.lang.invoke.VarHandle$VarHandleDesc$Kind.<clinit>(VarHandle.java:2132)
at java.base/java.lang.invoke.VarHandle$2.<clinit>(VarHandle.java:2143)
at java.base/java.lang.invoke.VarHandle$AccessType.accessModeType(VarHandle.java:1554)
at java.base/java.lang.invoke.VarHandleReferences$FieldInstanceReadOnly.accessModeTypeUncached(VarHandleReferences.java:59)
at java.base/java.lang.invoke.VarHandle.accessModeType(VarHandle.java:1919)
at java.base/java.lang.invoke.VarHandle.getMethodHandleUncached(VarHandle.java:2020)
at java.base/java.lang.invoke.VarHandle.getMethodHandle(VarHandle.java:2015)
at java.base/java.lang.invoke.Invokers.checkVarHandleGenericType(Invokers.java:453)
at java.base/java.util.concurrent.ConcurrentSkipListMap.doPut(ConcurrentSkipListMap.java:606)
at java.base/java.util.concurrent.ConcurrentSkipListMap.merge(ConcurrentSkipListMap.java:1556)
at java.base/java.net.SocketPermissionCollection.add(SocketPermission.java:1381)
at java.base/java.security.Permissions.add(Permissions.java:132)
at java.base/sun.security.provider.PolicyFile.addPerms(PolicyFile.java:1339)
at java.base/sun.security.provider.PolicyFile.addPermissions(PolicyFile.java:1196)
at java.base/sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1140)
at java.base/sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1104)
at java.base/sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1044)
at java.base/sun.security.provider.PolicyFile.implies(PolicyFile.java:1000)
at java.base/java.security.ProtectionDomain.implies(ProtectionDomain.java:321)
at java.base/java.security.ProtectionDomain.impliesWithAltFilePerm(ProtectionDomain.java:353)
at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:450)
at java.base/java.security.AccessController.checkPermission(AccessController.java:1042)
at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:408)
at java.base/java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1324)
at java.base/java.lang.ClassLoader$1.run(ClassLoader.java:690)
at java.base/java.lang.ClassLoader$1.run(ClassLoader.java:688)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.base/java.lang.ClassLoader.checkPackageAccess(ClassLoader.java:688)
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:761)
at java.base/jdk.internal.loader.BuiltinClassLoader.lambda$findClassInModuleOrNull$2(BuiltinClassLoader.java:684)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:685)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:563)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
at java.base/java.lang.Class.forName(Class.java:493)
at java.base/java.util.ServiceLoader.lambda$loadProvider$1(ServiceLoader.java:858)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:860)
... 20 more
Caused by: java.lang.ClassCircularityError: sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:761)
at java.base/jdk.internal.loader.BuiltinClassLoader.lambda$findClassInModuleOrNull$2(BuiltinClassLoader.java:684)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:685)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:563)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
at java.base/java.lang.Class.forName(Class.java:493)
at java.base/java.util.ServiceLoader.lambda$loadProvider$1(ServiceLoader.java:858)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:860)
... 85 more