Project

Profile

Help

Bug #5564

closed

On Windows, SaxonCS Query command line -o:test.xml fails "The path is empty"

Added by Michael Kay almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Command Line
Sprint/Milestone:
-
Start date:
2022-06-14
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
11
Fix Committed on Branch:
11, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

If SaxonCS XQuery is called from the command line with the -o option and the filename includes no path component (e.g. -o:test.xml) it fails with the error

System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at Saxon.Ejava.io.File..ctor(String name)
   at Saxon.Ejava.io.File.getParentFile()

Workaround: use -o:./test.xml.

Actions #1

Updated by Michael Kay almost 2 years ago

For some reason, the XQuery code does

createFileIfNecessary(outputFile);
serializer = processor.newSerializer(new System.IO.FileStream(outputFile.getPath(), System.IO.FileMode.Create));
                      

while the Transform code simply does

serializer = processor.newSerializer(outputFile);

The same difference is present in the Java code.

Actions #2

Updated by Martin Honnen almost 2 years ago

I have also run into a similar error with -export:foo.sef.json, the same workaround -export:./foo.sef.json works, but I hope mentioning it here helps ironing out some quirks in the command line option handling of SaxonCS.

saxonxslt -t -xsl:sheet3.xsl -nogo -target:JS -relocate:on -export:sheet3.xsl.saxoncs-export.sef.json
SaxonCS-EE 11.3 from Saxonica
.NET 6.0.6 on Windows 10.0.22000.0
Using license serial number ..
System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at Saxon.Ejava.io.File..ctor(String name)
   at Saxon.Ejava.io.File.getParentFile()
   at Saxon.Hej.Query.createFileIfNecessary(File file)
   at Saxon.Hej.s9api.XsltPackage.save(File file, String target)
   at Saxon.Hej.s9api.XsltPackage.save(File file)
   at Saxon.Hej.Transform.doTransform(String[] args)
Fatal error during transformation: ArgumentException: The path is empty. (Parameter 'path')
Exiting with code 2
Actions #3

Updated by Michael Kay almost 2 years ago

I haven't actually reproduced the problem yet. It seems to work fine on Mac. I'll have to try it on Windows when I'm back in the office.

Actions #4

Updated by Michael Kay over 1 year ago

I've now revived my Windows machine and reproduced the problem.

Actions #5

Updated by Michael Kay over 1 year ago

The problem is with the call on Query.createFileIfNecessary().

Changing the code to simply call newSerializer(outputFile), as Transform does, solves the problem.

The only other place that invokes Query.createFileIfNecessary() in SaxonCS is XsltPackage.save(), which fits with Martin's observation of a similar problem with -export.

Actions #6

Updated by Michael Kay over 1 year ago

I've reproduced the problem with -export.

Query.createFileIfNecessary() is calling Saxon's C# emulation of java.io.File.getParentFile() which is implemented as return new File(System.IO.Path.GetDirectoryName(fileName));. The call on new File() calls System.IO.Path.getFullPath(), which fails because the result of GetDirectoryName() is null (or empty?). It's not clear why it works on Mac but fails on Windows.

The path in Processor.newSerializer(File), which is working, constructs a StreamResult object holding the File, then wraps this in an ExpandedStreamResult, and calls its obtainOutputStream() method to get an output stream for writing to the file.

Simply deleting the line Query.createFileIfNecessary() from XsltPackage.save() solves the problem - but we don't yet know what side-effects it has.

Actions #7

Updated by Michael Kay over 1 year ago

  • Subject changed from SaxonCS Query command line -o:test.xml fails "The path is empty" to On Windows, SaxonCS Query command line -o:test.xml fails "The path is empty"
Actions #8

Updated by Michael Kay over 1 year ago

  • Status changed from New to Resolved
  • Priority changed from Low to Normal
  • Applies to branch 11, trunk added

If I remove the call on createFileIfNecessary() from XsltPackage.save(), Transform -export:a/b/c/d/output.sef.xml fails in SaxonJ.

Actions #9

Updated by Michael Kay over 1 year ago

But that command fails anyway with the current code. Unless I also do -nogo.

Fixed that.

Specifically: the command

net.sf.saxon.Transform -s:test.xml -xsl:test.xsl -export:a/b/c/d/export.sef.xml

fails with a FileNotFoundException if the intermediate directories do not exist.

Actions #10

Updated by Michael Kay over 1 year ago

  • Applies to branch deleted (trunk)
  • Fix Committed on Branch 11, trunk added
  • Platforms Java added

Resolved.

Performed ad-hoc testing with a variety of command line options for Query -o and Transform -export, on SaxonJ, SaxonCS on Mac, and SaxonCS on Windows.

Actions #11

Updated by Debbie Lockett over 1 year ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 11.4 added

Bug fix applied in the Saxon 11.4 maintenance release.

Please register to edit this issue

Also available in: Atom PDF