Skip to content

Improve error report when trying to create a reserved filename #4781

@scabug

Description

@scabug

When running scalac or scaladoc on an object or a class named "Con" (case insensitive),
the program will not be able to produce the corresponding output file (Con.class or Con.html),
but rather throw an error or crash:

X:>scalac ReservedFilename.scala
error: The system cannot find the file specified
one error found

X:>scaladoc ReservedFilename.scala
Exception in thread "main" java.io.FileNotFoundException: .\Con.html (The system cannot find the file specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:179)
at java.io.FileOutputStream.(FileOutputStream.java:70)
at scala.tools.nsc.doc.html.HtmlPage.writeFor(HtmlPage.scala:57)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$generate$1.apply(HtmlFactory.scala:101)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$generate$1.apply(HtmlFactory.scala:101)
at scala.tools.nsc.doc.html.HtmlFactory.writeTemplate$1(HtmlFactory.scala:113)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$writeTemplate$1$1.apply(HtmlFactory.scala:115)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$writeTemplate$1$1.apply(HtmlFactory.scala:115)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
at scala.collection.immutable.List.map(List.scala:45)
at scala.tools.nsc.doc.html.HtmlFactory.writeTemplate$1(HtmlFactory.scala:115)
at scala.tools.nsc.doc.html.HtmlFactory.writeTemplates(HtmlFactory.scala:118)
at scala.tools.nsc.doc.html.HtmlFactory.generate(HtmlFactory.scala:101)
at scala.tools.nsc.doc.html.Doclet.generateImpl(Doclet.scala:10)
at scala.tools.nsc.doc.doclet.Generator.generate(Generator.scala:24)
at scala.tools.nsc.doc.DocFactory.generate$1(DocFactory.scala:117)
at scala.tools.nsc.doc.DocFactory.document(DocFactory.scala:120)
at scala.tools.nsc.ScalaDoc.process(ScalaDoc.scala:48)
at scala.tools.nsc.ScalaDoc$.main(ScalaDoc.scala:74)
at scala.tools.nsc.ScalaDoc.main(ScalaDoc.scala)

This is due to the "con" filename being a reserved one on Windows OS family (regardless of extension).

An improvement would be to detect when the filename "con" is about to be created and suggest an appropriate course of action instead of crashing. This could be anything ranging from a simple explanation (why the file cannot be created), a suggestion of renaming the object/class if possible or for instance, compiling on another OS and then packaging as a jar which would allow using the precompiled binaries on Windows.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions