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

Commit 79dc4ca5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Prevent variables with type java.lang.Boolean" into main

parents c3826075 9d36bca2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -135,7 +135,8 @@ class LogEnforcementVariableCreationDetector : Detector(), SourceCodeScanner {
        val fieldType = field.getType()
        val fieldName = field.getName()
        val fieldInitializer = field.uastInitializer?.skipParenthesizedExprDown()
        return fieldType.canonicalText.lowercase() == "boolean" &&
        return (fieldType.canonicalText == "boolean" ||
            fieldType.canonicalText == "java.lang.Boolean") &&
            (isLogEnforcementVariable(fieldName) ||
                (fieldInitializer != null &&
                    (checkExpressionForIsLoggableUsages(fieldInitializer) ||
+32 −0
Original line number Diff line number Diff line
@@ -779,6 +779,38 @@ class LogEnforcementVariableCreationDetectorTest : LintDetectorTest() {
            .expectClean()
    }

    @Test
    fun testVariableCreationWithBooleanWrapperClass_issuesFound() {
        lint()
            .files(
                java(
                        """
                package com.android.bluetooth;

                import android.util.Log;

                public final class Foo {
                    private static final String TAG = Foo.class.getSimpleName();
                    private static final Boolean WHYYYY_DBG = true;

                    public Foo() {
                        Log.d(TAG, "created Foo without an enforcement variable");
                    }
                }
                """
                    )
                    .indented(),
                *stubs
            )
            .issues(LogEnforcementVariableCreationDetector.ISSUE)
            .run()
            .expectContains(
                LogEnforcementVariableCreationDetector.LOG_ENFORCEMENT_VARIABLE_USAGE_ERROR
            )
            .expectContains(createErrorCountString(1, 0))
            .expectFixDiffs(createFixDiff(7, "    private static final Boolean WHYYYY_DBG = true;"))
    }

    private val logFramework: TestFile =
        java(
                """