Skip to content

Conversation

@asolovay
Copy link
Contributor

@asolovay asolovay commented Aug 4, 2025

Happened to notice a typo in the file, but it still didn't compile when I fixed the typo, so I made a second fix.

The typo was a missing semicolon at the "import AppCompatActivity" line. But after I fixed that, I got an error complaining about assertFalse(isLetterboxed(activity)) because isLetterboxed is expecting an AppCompatActivity but activity is a MainActivity. Changing isLetterboxed fixed the compile error and also meant we don't import AppCompatActivity so the original typo goes away. [shrug emoji]

Is this fix okay?

Happened to notice a typo in the file, but it still didn't compile when I fixed the
typo, so I made a second fix.

The typo was a missing semicolon at the "import AppCompatActivity" line. But after
I fixed that, I got an error complaining about `assertFalse(isLetterboxed(activity))`
because `isLetterboxed` is expecting an AppCompatActivity but `activity`
is a `MainActivity`. Changing `isLetterboxed` fixed the compile error and also
meant we don't import AppCompatActivity so the original typo goes away. [shrug emoji]

Is this fix okay?
@JonEckenrode
Copy link
Contributor

What was the typo, Andrew? I don't see where it was fixed. Also, these files compiled previously.

@asolovay
Copy link
Contributor Author

asolovay commented Aug 4, 2025

The typo was in line 19:
https://github.com/android/snippets/blob/main/misc/src/androidTest/java/com/example/snippets/DeviceCompatibilityModeTestJavaSnippets.java#L19

import androidx.appcompat.app.AppCompatActivity
import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.rules.ActivityScenarioRule;

(note the lack of a semicolon at the end of the first line).

But when I fixed that typo, the file still wouldn't compile, because isLetterBoxed() expects to be passed an AppCompatActivity but it's actually being passed a MainActivity.

When I changed the isLetterBoxed method to be passed a MainActivity, everything compiles -- but since the file no longer needs AppCompatActivity, AndroidStudio removed that "import AppCompatActivity" line, so the typo fix went away.

...just to confirm, when you submitted it, did you compile the AndroidTest module? I don't see how it could have compiled with that missing semicolon.

Copy link
Contributor

@alexvanyo alexvanyo left a comment

Choose a reason for hiding this comment

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

Update looks good here!

This never would have compiled - but it wasn't being caught on CI because this particular set of code underneath androidTest isn't being built and verified on CI.

I reported #576 for the bigger issue here of not validating snippets in instrumented test sources.


// Method used by snippets.
public boolean isLetterboxed(AppCompatActivity activity) {
public boolean isLetterboxed(MainActivity activity) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you move to MainActivity instead of AppCompatActivity?
If the problem was a ; missing, this shouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned above -- when I added the semicolon I still couldn't compile, because isLetterBoxed() 's return value was being passed to something that expected a MainActivity. I don't know if this was the best way to fix that but it works and it doesn't change the code that's actually included in the docs, so 🤷

Thanks for submitting!

@florina-muntenescu florina-muntenescu merged commit c703008 into main Aug 5, 2025
5 checks passed
@florina-muntenescu florina-muntenescu deleted the testFix branch August 5, 2025 12:46
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.

5 participants