You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The javalib Files.createTempFile method loops infinitely when given a Path argument which
does not exist. Presumably its createTempDirectory kin all have a similar loop.
Later:
Yes, at least one createTempDirectory method exhibits the loop.
It appears that the reported problem can occur (only?) with the methods which
take a Path as the first argument. The others usually default to the system temporary
directory, which should exist. There may be a way for a user to set the a Property to
change the temporary directory for that user to someplace bogus. In that case
the same defect would become evident.
The fix is the same in all cases.
Analysis
FileHelpers.scala allows doing something dumb, then the Files methods goes ahead
and does it.
From FileHelpers.scala:
while ({
result = genTempFile(prefix, newSuffix, tmpDir)
!createNewFile(result.toString, throwOnError)
}) ()
Consider the case where the throwOnError argument is passed in as "false" and createNewFile continually returns false, say because the dir argument pased in does
not exist or can not be created, say because it is non-writable.
Those are conditions which are unlikely to be be changed by re-try. Yes, it could
happen, but not the expected case.
The FilescreateTemp* methods call FileHelper methods which default throwOnError to
"false", so they loop until the end of time when they pass down an argument which causes
errors in the underlying code.
The Files methods under consideration are documented as being capable of returning IoException and its sub-classes. Allowing the underlying code to throw an Exception
would give the end user some clue as to the nature of the problem.
Someday, the FileHelpers code should be fixed. One can add a counter, but what should
it do when it has been explicitly told to not throw on error? I think the most robust thing
to do is to throw an IoException stating that the counter limit has been exceeded.
Either that require that the code execute on more cores so that the loop completes
faster.
The text was updated successfully, but these errors were encountered:
LeeTibbert
added a commit
to LeeTibbert/scala-native-fork
that referenced
this issue
Feb 9, 2024
LeeTibbert
changed the title
Infinite loops in javalib Files.createTempFile and createDirectoryFile* methods
Infinite loops in javalib Files.createTempFile and createTempDirectory* methods
Feb 9, 2024
Presenting problem
The javalib
Files.createTempFile
method loops infinitely when given a Path argument whichdoes not exist. Presumably its
createTempDirectory
kin all have a similar loop.Later:
Yes, at least one
createTempDirectory
method exhibits the loop.It appears that the reported problem can occur (only?) with the methods which
take a
Path
as the first argument. The others usually default to the system temporarydirectory, which should exist. There may be a way for a user to set the a Property to
change the temporary directory for that user to someplace bogus. In that case
the same defect would become evident.
The fix is the same in all cases.
Analysis
FileHelpers.scala
allows doing something dumb, then theFiles
methods goes aheadand does it.
From
FileHelpers.scala
:Consider the case where the throwOnError argument is passed in as "false" and
createNewFile continually returns false, say because the dir argument pased in does
not exist or can not be created, say because it is non-writable.
Those are conditions which are unlikely to be be changed by re-try. Yes, it could
happen, but not the expected case.
The
Files
createTemp*
methods callFileHelper
methods which default throwOnError to"false", so they loop until the end of time when they pass down an argument which causes
errors in the underlying code.
The
Files
methods under consideration are documented as being capable of returningIoException
and its sub-classes. Allowing the underlying code to throw an Exceptionwould give the end user some clue as to the nature of the problem.
Someday, the
FileHelpers
code should be fixed. One can add a counter, but what shouldit do when it has been explicitly told to not throw on error? I think the most robust thing
to do is to throw an IoException stating that the counter limit has been exceeded.
Either that require that the code execute on more cores so that the loop completes
faster.
The text was updated successfully, but these errors were encountered: