Skip to content

Conversation

@asolovay
Copy link
Contributor

I'd submitted code that's never actually used in the android/snippets apps. Ideally we'd include it in an app, but in the meantime, disabling the "unused" warnings.

Also removed one line (outside of a published-on-DAC code block) that turned out not to be needed.

No changes to the code that's included on DAC, and the code still compiles.

I'd submitted code that's never actually used in the android/snippets apps. Ideally we'd include it in an app, but in the meantime, disabling the "unused" warnings.

Also removed one line (outside of a published-on-DAC code block) that turned out not to be needed.

No changes to the code that's included on DAC, and the code still compiles.
@asolovay asolovay requested a review from cartland August 29, 2025 22:58
Copy link
Contributor

@cartland cartland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if you can use UNUSED_PARAMETER instead of UNUSED in one place. I also think we should use all capital letters.


import androidx.annotation.Nullable;

@SuppressWarnings("Unused")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java all caps:
@SuppressWarnings("UNUSED")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just wanted to confirm here that it's @SuppressWarnings() in Java, but @Suppress() in Kotlin?

Copy link
Contributor Author

@asolovay asolovay Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually -- when I amend my commit, I still get the warning "Method 'doSomethingAndRelease()' is never used" for this Java file (but not for the Kotlin file).

Is there something I'm doing wrong with @SuppressWarnings()? Right now I have:

    @SuppressWarnings("UNUSED")
    // [START android_backgroundwork_wakelock_release_java]
    void doSomethingAndRelease() throws MyException {
        try {
            wakeLock.acquire();
            doTheWork();
        } finally {
            wakeLock.release();
        }
    }
    // [END android_backgroundwork_wakelock_release_java]
   

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks reasonable to me. Can you clarify where you are seeing the morning? Is this in Android Studio or a when you run a command line lint command? I can try your steps to reproduce.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in Android Studio, when I try to push the commit to GitHub--it pops up a screen saying "there are these warnings, are you sure you want to push?"

But when I try compiling the "misc" module, I get no warnings. So if the answer is "pay attention to that, don't worry about the warning you get when you push", I'm happy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we need to use @SuppressWarnings("unused") in Java. Android Studio lint only respects this if the "unused" is lowercase.

I'm thinking we should use lower case for both Kotlin: @Suppress("unused") and Java @SuppressWarnings("unused"). The capitalized version only work in Kotlin, so I would prefer to be consistent across languages by using lowercase.

asolovay and others added 4 commits September 2, 2025 15:43
I'd submitted code that's never actually used in the android/snippets apps. Ideally we'd include it in an app, but in the meantime, disabling the "unused" warnings.

Also removed one line (outside of a published-on-DAC code block) that turned out not to be needed.

No changes to the code that's included on DAC, and the code still compiles.

(I also see some areas where the actual code snippet is generating warnings, but I'll resolve those in separate PRs that can be reviewed by the appropriate SMEs for those docs.)
I'd submitted code that's never actually used in the android/snippets apps. Ideally we'd include it in an app, but in the meantime, disabling the "unused" warnings.

Also removed one line (outside of a published-on-DAC code block) that turned out not to be needed.

No changes to the code that's included on DAC, and the code still compiles.

(I also see some areas where the actual code snippet is generating warnings, but I'll resolve those in separate PRs that can be reviewed by the appropriate SMEs for those docs.)
…-code-cleanup

# Conflicts:
#	misc/src/main/java/com/example/snippets/PreloadManagerKotlinSnippets.kt
#	misc/src/main/java/com/example/snippets/backgroundwork/WakeLockSnippetsJava.java
#	misc/src/main/java/com/example/snippets/backgroundwork/WakeLockSnippetsKotlin.kt
@asolovay
Copy link
Contributor Author

asolovay commented Sep 2, 2025

Cartland -- I made the updates you suggested, but I still seem to get a warning in WakeLockSnippetsJava.doSomethingAndRelease(). Can you see what I'm doing wrong there? Thanks much!

@cartland
Copy link
Contributor

cartland commented Sep 3, 2025

I think we need to use the lowercase version of Kotlin Suppress("unused") and Java @SuppressWarnings("unused"). In Java, Android Studio will help you add the Java annotation if you click Code -> Inspect Code then find a warning and click "Suppress". The Kotlin annotation will add a /** @noinspection unused*/ comment but I think the annotation Suppress("unused") is better than the comment. However, the Android Studio "Suppress" tool is probably the easiest way to find the name of the warning that you want to suppress, since this should work for other types of warnings (not just unused code).

Suppress

@asolovay
Copy link
Contributor Author

asolovay commented Sep 3, 2025

I think we need to use the lowercase version of Kotlin Suppress("unused") and Java @SuppressWarnings("unused"). In Java, Android Studio will help you add the Java annotation if you click Code -> Inspect Code then find a warning and click "Suppress". The Kotlin annotation will add a /** @noinspection unused*/ comment but I think the annotation Suppress("unused") is better than the comment. However, the Android Studio "Suppress" tool is probably the easiest way to find the name of the warning that you want to suppress, since this should work for other types of warnings (not just unused code).

Just to be clear, are you asking me to change all the @Suppress("UNUSED") / @SuppressWarnings("UNUSED") to lowercase "unused"? Or are you just saying "that would clear the Android Studio warning but it's not necessary for this PR"?

@asolovay asolovay requested a review from cartland September 3, 2025 19:16
@asolovay
Copy link
Contributor Author

asolovay commented Sep 3, 2025

Just to be clear, are you asking me to change all the @Suppress("UNUSED") / @SuppressWarnings("UNUSED") to lowercase "unused"? Or are you just saying "that would clear the Android Studio warning but it's not necessary for this PR"?

Per our chat, I'll change all the suppress parameters to lower-case and re-push, stay tuned!

I was getting some warnings in Java code that should have been suppressed. It looks like this is because Java expects the @SuppressWarnings parameters to be in lowercase. Kotlin doesn't seem to care about case, but I'm changing those ones too to be consistent.
@asolovay
Copy link
Contributor Author

asolovay commented Sep 3, 2025

It looks like changing to "unused" fixed that warning! (I have one other unrelated warning, but it's about code that's on DAC so I'll want to do it in a separate CL where I can get the SME's approval.)

Let me know if you see any more issues.

Copy link
Contributor

@cartland cartland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@asolovay asolovay merged commit 3d5181b into main Sep 3, 2025
5 checks passed
@asolovay asolovay deleted the unused-code-cleanup branch September 3, 2025 22:30
dturner added a commit that referenced this pull request Sep 23, 2025
* main: (74 commits)
  Add basic WindowInsetsRulers cases (#621)
  Adding shadows code snippets (#620)
  Update the wear preview code
  Update state based (#619)
  add WindowInsetsRulers snippet (#616)
  Migrate snippets from dac/training/wearables/tiles/screen-size (#617)
  Resolve warnings in the Wakelock code snippets (#615)
  Disabling some "unused" warnings (#610)
  Add android_wear_tile_version_fallback (#614)
  Add viewmodel screen for KMP (#613)
  Fix missing snippet (#612)
  Add KMP ViewModel snippets (#611)
  docs(modifiers): Add TODOs for inspectableProperties lint warnings (#589)
  Fix: Prevent memory leak from implicit SAM conversion (#588)
  Fix(gestures): Handle pointer events inside awaitPointerEventScope (#590)
  Lint: Use specialized state holders to avoid autoboxing (#591)
  Refactor: Rename Composable functions to follow naming conventions (#592)
  Refactor(text): Use KTX extension for isDigitsOnly check (#593)
  Refactor(SearchBar): Reorder modifier parameter to follow convention (#594)
  Add padding to avoid overwriting TimeText (#529)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants