R8: не проверяет тип и будет считаться недоступным - PullRequest
1 голос
/ 12 января 2020

При включении android.enableR8.fullMode=true я получаю следующее предупреждение:

AGPBI: {
    "kind": "warning",
    "text": "The method `void org.apache.commons.logging.impl.Log4JLogger.<clinit>()`
             does not type check and will be assumed to be unreachable.",
    "sources": [{}],
    "tool": "R8"
}

Как сохранить экспансию org.apache.commons.logging.impl.Log4JLogger.<clinit>() с R8? android.enableR8.fullMode=false (настройка по умолчанию) - неприемлемое решение, даже если инициализатор static <clinit> не будет оптимизирован подобным образом. Удаляемый код: this :

// ------------------------------------------------------------
// Static Initializer.
//
// Note that this must come after the static variable declarations
// otherwise initialiser expressions associated with those variables
// will override any settings done here.
//
// Verify that log4j is available, and that it is version 1.2.
// If an ExceptionInInitializerError is generated, then LogFactoryImpl
// will treat that as meaning that the appropriate underlying logging
// library is just not present - if discovery is in progress then
// discovery will continue.
// ------------------------------------------------------------

static {
    if (!Priority.class.isAssignableFrom(Level.class)) {
        // nope, this is log4j 1.3, so force an ExceptionInInitializerError
        throw new InstantiationError("Log4J 1.2 not available");
    }

    // Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
    // versions do not. If TRACE is not available, then we have to map
    // calls to Log.trace(...) onto the DEBUG level.

    Priority _traceLevel;
    try {
        _traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
    } catch(Exception ex) {
        // ok, trace not available
        _traceLevel = Level.DEBUG;
    }
    traceLevel = _traceLevel;
}

1 Ответ

0 голосов
/ 13 января 2020

Это работает, как задумано, и подробности анализа можно увидеть в http://issuetracker.google.com/146478391.

Возможное решение также присутствует, что включает в себя убедиться, что связь между уровнем и приоритетом (уровень расширяет приоритет) известна компиляции R8.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...