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

Commit be520f1e authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Revert^2 "Handle null object params"

1688d1db

Change-Id: I0114d933be46206f44e3a06ecd0138851d0a0587
parent 3a231685
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -476,13 +476,25 @@ public class PerfettoProtoLogImpl implements IProtoLog {
                                needsIncrementalState = true;
                                break;
                            case LogDataType.LONG:
                                if (o == null) {
                                    longParams.add(0);
                                } else {
                                    longParams.add(((Number) o).longValue());
                                }
                                break;
                            case LogDataType.DOUBLE:
                                if (o == null) {
                                    doubleParams.add(0d);
                                } else {
                                    doubleParams.add(((Number) o).doubleValue());
                                }
                                break;
                            case LogDataType.BOOLEAN:
                                if (o == null) {
                                    booleanParams.add(false);
                                } else {
                                    booleanParams.add((boolean) o);
                                }
                                break;
                        }
                    } catch (ClassCastException ex) {
+23 −0
Original line number Diff line number Diff line
@@ -711,6 +711,29 @@ public class PerfettoProtoLogImplTest {
                .isEqualTo("My test null string: null");
    }

    @Test
    public void supportNullParams() throws IOException {
        PerfettoTraceMonitor traceMonitor =
                PerfettoTraceMonitor.newBuilder().enableProtoLog(true)
                        .build();

        try {
            traceMonitor.start();

            mProtoLog.log(LogLevel.DEBUG, TestProtoLogGroup.TEST_GROUP,
                    "My null args: %d, %f, %b", null, null, null);
        } finally {
            traceMonitor.stop(mWriter);
        }

        final ResultReader reader = new ResultReader(mWriter.write(), mTraceConfig);
        final ProtoLogTrace protolog = reader.readProtoLogTrace();

        Truth.assertThat(protolog.messages).hasSize(1);
        Truth.assertThat(protolog.messages.get(0).getMessage())
                .isEqualTo("My null args: 0, 0, false");
    }

    private enum TestProtoLogGroup implements IProtoLogGroup {
        TEST_GROUP(true, true, false, "TEST_TAG");