Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Fix NPE when listing files in screenshot folder #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer/src/main/kotlin/com/gojuno/composer/TestRun.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private fun pullTestFiles(adbDevice: AdbDevice, test: InstrumentationTest, outpu
PulledFiles(
files = emptyList(), // TODO: Pull test files.
screenshots = screenshotsFolderOnHostMachine.let {
when (it.exists()) {
when (it.exists() && it.listFiles() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

listFiles() can return null only if it is not a directory. Calling exists() beforehand is partially redundant IMHO.
There is also a race condition possible when directory is removed in the time between two listFiles() calls.

What about replacing when block with it.listFiles()?.toList() ?: emptyList() ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about when (it.exists() && it.isDirectory())?

Race condition is still possible with it.listFiles()?.toList() ?: emptyList() since we're going to get problems later during adb pull if list of files is invalid

Copy link
Contributor

Choose a reason for hiding this comment

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

isDirectory() returns false if there is no directory under given path including the case when there is nothing there.

we're going to get problems later during adb pull if list of files is invalid

It seems that screenshots have been already pulled when we are listing those files:
https://github.com/rafakob/composer/blob/f70e773c73adc6e7f98ffaf85f0000d5f8675ee4/composer/src/main/kotlin/com/gojuno/composer/TestRun.kt#L164

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah right, my bad

returns false if there is no directory under given path including the case when there is nothing there.

Isn't that what we want?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but listFiles() != null also checks for existence.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well for sake of removing redundancy from if statement I'm 👍 with using listFiles() != null

true -> it.listFiles().toList()
else -> emptyList()
}
Expand Down