-
Notifications
You must be signed in to change notification settings - Fork 45
Fix NPE when listing files in screenshot folder #124
base: master
Are you sure you want to change the base?
Conversation
@@ -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) { |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
How to reproduce this NPE?
Composer code doesn't seem to be touching it, creating parent
In this case, I think proposed solution to silently ignoring NPE is incorrect. Because |
listFiles()
may return null which leads to crash: