MissingResourceException: cannot find package for base name sun.util.logging.resources.logging, locale en_US

I get,

Caused by java.lang.InternalError: java.util.MissingResourceException: Can't find bundle for base name sun.util.logging.resources.logging, locale en_US 

in my application from firebase crash report.

Other information

 Manufacturer: HTC Model: HTC 10 Android API: 24 

Here is the stack trace

 java.util.logging.Logger$1.run (Logger.java:1385) java.util.logging.Logger$1.run (Logger.java:1379) java.security.AccessController.doPrivileged (AccessController.java:41) java.util.logging.Logger.findSystemResourceBundle (Logger.java:1378) java.util.logging.Logger.findResourceBundle (Logger.java:1425) java.util.logging.Logger.setupResourceInfo (Logger.java:1523) java.util.logging.Logger.<init> (Logger.java:266) java.util.logging.Logger.<init> (Logger.java:261) java.util.logging.LogManager$SystemLoggerContext.demandLogger (LogManager.java:734) java.util.logging.LogManager.demandSystemLogger (LogManager.java:399) java.util.logging.Logger.getPlatformLogger (Logger.java:474) java.util.logging.LoggingProxyImpl.getLogger (LoggingProxyImpl.java:41) sun.util.logging.LoggingSupport.getLogger (LoggingSupport.java:100) sun.util.logging.PlatformLogger$JavaLoggerProxy.<init> (PlatformLogger.java:636) sun.util.logging.PlatformLogger$JavaLoggerProxy.<init> (PlatformLogger.java:631) sun.util.logging.PlatformLogger.<init> (PlatformLogger.java:246) sun.util.logging.PlatformLogger.getLogger (PlatformLogger.java:205) java.net.CookieManager.put (CookieManager.java:262) okhttp3.JavaNetCookieJar.saveFromResponse (JavaNetCookieJar.java:47) okhttp3.internal.http.HttpHeaders.receiveHeaders (HttpHeaders.java:182) okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:95) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:120) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:67) okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:185) okhttp3.RealCall.execute (RealCall.java:69) 

Here is the corresponding registrar code

 private static ResourceBundle findSystemResourceBundle(final Locale var0) { return (ResourceBundle)AccessController.doPrivileged(new PrivilegedAction() { public ResourceBundle run() { try { return ResourceBundle.getBundle("sun.util.logging.resources.logging", var0, ClassLoader.getSystemClassLoader()); } catch (MissingResourceException var2) { throw new InternalError(var2.toString()); } } }); } 

I have a en_AU report for locale en_AU too.

Since the failure code is not controlled by me, how can I prevent this failure?

+5
source share
2 answers

Analysis:

MissingResourceException: cannot find package for base name sun.util.logging.resources.logging, locale en_US

The system generates candidate pool names

 sun/util/logging/resources/logging_en_US sun/util/logging/resources/logging_en sun/util/logging/resources/logging 

For each candidate bundle name, he tries to download a resource package:

He first tries to load the class using the generated class name.

If such a class can be found and loaded using the specified class, the loader is compatible with the ResourceBundle, accessible from the ResourceBundle and can be created, getBundle creates a new instance of this class and uses it as the resulting resource package.

Otherwise, getBundle tries to find the resource resource file using the file name of the generated properties.

It generates a path name from the name of the candidate bundle, replacing all with ".". characters with "/" and adding the string ".properties". He tries to find a "resource" with this name using java.lang.ClassLoader.getResource (java.lang.String). (Note that a โ€œresourceโ€ in the sense of getResource has nothing to do with the contents of a resource package, it's just a data container, such as a file.) If it finds a โ€œresourceโ€, it tries to create a new PropertyResourceBundle from its contents. If successful, this instance becomes the resulting resource package.

See here how the registry is resolved in more detail.

Since the system looks for the class path for any of these files in descending order (usually there is no _en * .properties)

 sun/util/logging/resources/logging_en_US.properties sun/util/logging/resources/logging_en.properties sun/util/logging/resources/logging.properties 

it would be a workaround to add such a file (or class as above) to your application. The contents of the property files look like this :

 # Localizations for Level names. For the US locale # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. ALL=All # The following ALL CAPS words should be translated. SEVERE=Severe # The following ALL CAPS words should be translated. WARNING=Warning # The following ALL CAPS words should be translated. INFO=Info # The following ALL CAPS words should be translated. CONFIG= Config # The following ALL CAPS words should be translated. FINE=Fine # The following ALL CAPS words should be translated. FINER=Finer # The following ALL CAPS words should be translated. FINEST=Finest # The following ALL CAPS words should be translated. OFF=Off 
+3
source

If it works, the resource file suggested by another answer is the best option, but if that doesn't happen, I have another option. Assuming you don't need to keep a log, you should disable it like this:

 try { Class<?> cls = Class.forName("sun.util.logging.PlatformLogger"); Field field = cls.getDeclaredField("loggingEnabled"); field.setAccessible(true); field.set(null, Boolean.FALSE); } catch(Exception e) { // Failed } 

If you do this earlier, PlatformLogger should build DefaultLoggerProxy instead of JavaLoggerProxy, so broken code will never work. This is ugly, since it depends on the internal implementation details and since it disables logging, but maybe it works for your application?

+3
source

Source: https://habr.com/ru/post/1269217/


All Articles