6

我正进入(状态,

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

在我的firebase崩溃报告中的应用程序中。

其他详情

Manufacturer: HTC
Model: HTC 10 
Android API: 24 

这是堆栈跟踪

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)

这是相关的记录器代码

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());
                }
            }
        });
    }

我也有语言环境的崩溃报告en_AU

由于崩溃代码不是我控制的,我该如何防止这种崩溃?

4

2 回答 2

5

分析:

MissingResourceException:找不到基本名称 sun.util.logging.resources.logging 的捆绑包,语言环境 en_US

系统生成候选捆绑包名称

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

对于每个候选包名称,它会尝试加载一个资源包:

首先,它尝试使用生成的类名加载一个类。

如果可以使用指定的类加载器找到并加载这样的类,与 ResourceBundle 的分配兼容,可以从 ResourceBundle 访问,并且可以实例化,则 getBundle 会创建此类的新实例并将其用作结果资源包。

否则,getBundle 会尝试使用生成的属性文件名来定位属性资源文件。

它通过替换所有“。”从候选包名称生成路径名称。带有“/”的字符并附加字符串“.properties”。它尝试使用 java.lang.ClassLoader.getResource(java.lang.String) 查找具有此名称的“资源”。(请注意,getResource 意义上的“资源”与资源包的内容无关,它只是数据的容器,例如文件。)如果找到“资源”,它会尝试创建从其内容中创建一个新的 PropertyResourceBundle 实例。如果成功,此实例将成为结果资源包。

在这里更详细地查看资源是如何解决的。

由于系统在类路径中按降序查找这些文件中的任何一个(通常没有 _en*.properties)

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

将这样的文件(或上面提到的类)添加到您的应用程序将是一种解决方法。属性文件的内容如下所示

# 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
于 2017-07-05T06:43:55.303 回答
3

如果它像其他答案所建议的那样工作资源文件是一个更好的选择,但如果这没有成功,我还有另一个选择。假设您不需要日志记录,您应该能够像这样禁用它:

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
}

如果您尽早这样做,PlatformLogger 应该构造 DefaultLoggerProxy 而不是 JavaLoggerProxy,因此损坏的代码永远不会运行。这很丑陋,因为它取决于内部实现细节并且它禁用了日志记录,但也许它适用于您的应用程序?

于 2017-07-05T08:40:54.693 回答