Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d98f3df authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Fix NPE in LegacyProtoLogImpl

To avoid an allocation when there are no args, the ProtoLog code processor passes null instead of the args object array.

This CL also adds a @Nullable annotation to the args parameter in the log() method, to make it clear that the parameter can be null.

Flag: EXEMPT bug fix
Bug: 351324791
Bug: 351458758
Change-Id: I2f132a4eaa42c6a22231fbb9d33204052843047e
parent be520f1e
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ public class LegacyProtoLogImpl implements IProtoLog {
    @VisibleForTesting
    @Override
    public void log(LogLevel level, IProtoLogGroup group, long messageHash, int paramsMask,
            Object[] args) {
            @Nullable Object[] args) {
        if (group.isLogToProto()) {
            logToProto(messageHash, paramsMask, args);
        }
@@ -113,7 +113,8 @@ public class LegacyProtoLogImpl implements IProtoLog {
                "Not implemented. Only implemented for PerfettoProtoLogImpl.");
    }

    private void logToLogcat(String tag, LogLevel level, long messageHash, Object[] args) {
    private void logToLogcat(String tag, LogLevel level, long messageHash,
            @Nullable Object[] args) {
        String message = null;
        final String messageString = mViewerConfig.getViewerString(messageHash);
        if (messageString != null) {
@@ -129,9 +130,11 @@ public class LegacyProtoLogImpl implements IProtoLog {
        }
        if (message == null) {
            StringBuilder builder = new StringBuilder("UNKNOWN MESSAGE (" + messageHash + ")");
            if (args != null) {
                for (Object o : args) {
                    builder.append(" ").append(o);
                }
            }
            message = builder.toString();
        }
        passToLogcat(tag, level, message);