Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StrictXmir throws "Premature end of file." #3684

Closed
volodya-lombrozo opened this issue Dec 16, 2024 · 31 comments
Closed

StrictXmir throws "Premature end of file." #3684

volodya-lombrozo opened this issue Dec 16, 2024 · 31 comments

Comments

@volodya-lombrozo
Copy link
Member

I have updated eo to 0.49.1 and StrictXmir now gives me the following error:

Caused by: java.lang.IllegalStateException: org.xml.sax.SAXParseException; systemId: file:////Users/runner/work/jeo-maven-plugin/jeo-maven-plugin/target/its/spring-fat/target/xsd/XMIR-0.49.1.xsd; lineNumber: 1; columnNumber: 1; Premature end of file.
    at com.jcabi.xml.StrictXML.validate (StrictXML.java:299)
    at com.jcabi.xml.StrictXML.<init> (StrictXML.java:93)
    at com.jcabi.xml.StrictXML.<init> (StrictXML.java:84)
    at com.jcabi.xml.StrictXML.<init> (StrictXML.java:74)
    at org.eolang.parser.StrictXmir.<init> (StrictXmir.java:84)
    at org.eolang.parser.StrictXmir.<init> (StrictXmir.java:75)
    at org.eolang.jeo.representation.VerifiedEo.asXml (VerifiedEo.java:72)
    at org.eolang.jeo.representation.MeasuredEo.asXml (MeasuredEo.java:58)
    at org.eolang.jeo.representation.BytecodeRepresentation.toEO (BytecodeRepresentation.java:117)
    at org.eolang.jeo.Disassembling.transform (Disassembling.java:86)
    at org.eolang.jeo.Caching.tryTransform (Caching.java:93)
    at org.eolang.jeo.Caching.transform (Caching.java:63)
    at org.eolang.jeo.Logging.transform (Logging.java:83)
    at org.eolang.jeo.Disassembler.disassemble (Disassembler.java:113)
    at org.eolang.jeo.ParallelTranslator.translate (ParallelTranslator.java:70)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:197)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1708)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
    at java.util.stream.ForEachOps$ForEachTask.compute (ForEachOps.java:291)
    at java.util.concurrent.CountedCompleter.exec (CountedCompleter.java:754)
    at java.util.concurrent.ForkJoinTask.doExec (ForkJoinTask.java:387)
    at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec (ForkJoinPool.java:1312)
    at java.util.concurrent.ForkJoinPool.scan (ForkJoinPool.java:1843)
    at java.util.concurrent.ForkJoinPool.runWorker (ForkJoinPool.java:1808)
    at java.util.concurrent.ForkJoinWorkerThread.run (ForkJoinWorkerThread.java:188)
Caused by: org.xml.sax.SAXParseException: Premature end of file.
    at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException (Util.java:75)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate (DOMValidatorHelper.java:194)
    at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate (ValidatorImpl.java:108)
    at javax.xml.validation.Validator.validate (Validator.java:124)
    at com.jcabi.xml.StrictXML.validate (StrictXML.java:282)
    at com.jcabi.xml.StrictXML.<init> (StrictXML.java:93)
    at com.jcabi.xml.StrictXML.<init> (StrictXML.java:84)
    at com.jcabi.xml.StrictXML.<init> (StrictXML.java:74)
    at org.eolang.parser.StrictXmir.<init> (StrictXmir.java:84)
    at org.eolang.parser.StrictXmir.<init> (StrictXmir.java:75)
    at org.eolang.jeo.representation.VerifiedEo.asXml (VerifiedEo.java:72)
    at org.eolang.jeo.representation.MeasuredEo.asXml (MeasuredEo.java:58)
    at org.eolang.jeo.representation.BytecodeRepresentation.toEO (BytecodeRepresentation.java:117)
    at org.eolang.jeo.Disassembling.transform (Disassembling.java:86)
    at org.eolang.jeo.Caching.tryTransform (Caching.java:93)
    at org.eolang.jeo.Caching.transform (Caching.java:63)
    at org.eolang.jeo.Logging.transform (Logging.java:83)
    at org.eolang.jeo.Disassembler.disassemble (Disassembler.java:113)
    at org.eolang.jeo.ParallelTranslator.translate (ParallelTranslator.java:70)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:197)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1708)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
    at java.util.stream.ForEachOps$ForEachTask.compute (ForEachOps.java:291)
    at java.util.concurrent.CountedCompleter.exec (CountedCompleter.java:754)
    at java.util.concurrent.ForkJoinTask.doExec (ForkJoinTask.java:387)
    at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec (ForkJoinPool.java:1312)
    at java.util.concurrent.ForkJoinPool.scan (ForkJoinPool.java:1843)
    at java.util.concurrent.ForkJoinPool.runWorker (ForkJoinPool.java:1808)
    at java.util.concurrent.ForkJoinWorkerThread.run (ForkJoinWorkerThread.java:188)

The exception doesn't tell anything about the xmir that causes exception. Here is the full log:
build.log

@volodya-lombrozo
Copy link
Member Author

@yegor256 Could you take a look, please?

@yegor256
Copy link
Member

@volodya-lombrozo what is in this file? /Users/runner/work/jeo-maven-plugin/jeo-maven-plugin/target/its/spring-fat/target/xsd/XMIR-0.49.1.xsd

@volodya-lombrozo
Copy link
Member Author

@yegor256 Hope it will help:
XMIR-0.49.1.xsd.txt

@yegor256
Copy link
Member

@volodya-lombrozo this is very strange, since the XSD is valid. The exception message means that the file has zero length (this is usually what this exception means). Are you sure the file is not deleted while application is still running?

@volodya-lombrozo
Copy link
Member Author

@yegor256 I don't modify this file in any way.
Here is a failed pipeline where the issue occurred: Pipeline Link

I also archive the file structure in case of an error. You can download it here. As you can see, the file target/its/spring-fat/target/xsd/XMIR-0.49.1.xsd is located there.

@yegor256
Copy link
Member

@maxonfjvipon I have no idea why this may happen, maybe you can help?

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Dec 17, 2024

@yegor256 it seems to me that the problem in the path: file:////Users/runner/work/jeo-maven-plugin/jeo-maven-plugin/target/its/spring-fat/target/xsd/XMIR-0.49.1.xsd. Four slashes after file: is to much, ever for absolute path. I've never seen four, three is maximum

@yegor256
Copy link
Member

yegor256 commented Dec 17, 2024

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Dec 17, 2024

@yegor256 this is what ChatGTP is saying about these slashes:

image

Here we have four:

Caused by: java.lang.IllegalStateException: org.xml.sax.SAXParseException; systemId: file:////Users/runner/work/jeo-maven-plugin/jeo-maven-plugin/target/its/spring-fat/target/xsd/XMIR-0.49.1.xsd; lineNumber: 1; columnNumber: 1; Premature end of file.

@maxonfjvipon
Copy link
Member

@yegor256 I believe the problem is here. Should be "file://%s". Here if your path is absolute (starts with /) - you'll get 3 slashes - which is good

yegor256 added a commit that referenced this issue Dec 17, 2024
@yegor256
Copy link
Member

yegor256 commented Dec 17, 2024

@maxonfjvipon without triple slash it doesn't work on Windows, b/c this path is wrong for Saxon: file://C:\Users\a.xsd, while this one is OK: file:///C:\Users\a.xsd

@maxonfjvipon
Copy link
Member

@yegor256 then the logic should be different for different OSs

@yegor256
Copy link
Member

yegor256 commented Dec 17, 2024

@maxonfjvipon pay attention, all tests work now, in StrictXmirTest, on both platforms (Unix and Win)

@maxonfjvipon
Copy link
Member

@maxonfjvipon not really, see: https://github.com/objectionary/eo/blob/master/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java#L78

@yegor256 I think the test is not good enough because it just checks you concatenates absolute path with slashes correctly inside StrictXmir. You concat, then you slice and get the same path. But full path with file:/// is still the same and incorrect I believe

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Dec 17, 2024

@yegor256 this is what ChatGPT is saying about windows local path:

image image

The drive (C:) must be prefixed with /

@yegor256
Copy link
Member

@maxonfjvipon no matter how we format the file path, the tests work -- Saxon finds the file. However, it doesn't find the file in JEO project. This is the problem.

@yegor256
Copy link
Member

@maxonfjvipon what I mean is that existing tests not only check the formatting of the file path. They actually run Saxon, letting it find the file.

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon @yegor256 Have you checked this one? It's a critical blocker.

@yegor256
Copy link
Member

@maxonfjvipon should be easy to fix, please use Together just added to the repo: #3694

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Dec 19, 2024

@yegor256 I've just written a simple unit test with Together:

@Test
@ExtendWith(MktmpResolver.class)
@ExtendWith(WeAreOnline.class)
void doesNotFailInMultipleThreads(@Mktmp final Path tmp) {
    final XML xml = StrictXmirTest.xmir("https://www.eolang.org/XMIR.xsd");
    Assertions.assertDoesNotThrow(
        new Together<>(
            thread -> new StrictXmir(xml).validate()
        )::asList
    );
}

And I'm getting this : org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.IllegalArgumentException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: org.xml.sax.SAXParseException; systemId: file:///Users/maxonfjvipon/code/java/eo/eo-parser/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.

Any idea what it means?

UPD. Full log:

Caused by: java.lang.IllegalArgumentException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: org.xml.sax.SAXParseException; systemId: file:///Users/maxonfjvipon/code/java/eo/eo-parser/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at com.yegor256.Together.iterator(Together.java:144)
	at com.yegor256.Together.asList(Together.java:171)
	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:71)
	... 6 more
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: org.xml.sax.SAXParseException; systemId: file:///Users/maxonfjvipon/code/java/eo/eo-parser/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at com.yegor256.Together.iterator(Together.java:139)
	... 8 more
Caused by: java.lang.IllegalStateException: org.xml.sax.SAXParseException; systemId: file:///Users/maxonfjvipon/code/java/eo/eo-parser/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at com.jcabi.xml.StrictXML.validate(StrictXML.java:299)
	at com.jcabi.xml.StrictXML.<init>(StrictXML.java:93)
	at com.jcabi.xml.StrictXML.<init>(StrictXML.java:84)
	at com.jcabi.xml.StrictXML.<init>(StrictXML.java:74)
	at org.eolang.parser.StrictXmir.<init>(StrictXmir.java:84)
	at org.eolang.parser.StrictXmirTest.lambda$doesNotFailInMultipleThreads$0(StrictXmirTest.java:76)
	at com.yegor256.Together.lambda$iterator$0(Together.java:130)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: org.xml.sax.SAXParseException; systemId: file:///Users/maxonfjvipon/code/java/eo/eo-parser/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:75)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:194)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:108)
	at java.xml/javax.xml.validation.Validator.validate(Validator.java:124)
	at com.jcabi.xml.StrictXML.validate(StrictXML.java:282)
	... 10 more

@yegor256
Copy link
Member

@maxonfjvipon this means exactly what we are trying to catch. Try this, it will work:

@Test
@ExtendWith(MktmpResolver.class)
@ExtendWith(WeAreOnline.class)
void doesNotFailInMultipleThreads(@Mktmp final Path tmp) {
    final XML xml = StrictXmirTest.xmir("https://www.eolang.org/XMIR.xsd");
    Assertions.assertDoesNotThrow(
        new Together<>(
            thread -> {
                synchronized (StrictXmir.class) {
                    return new StrictXmir(xml).validate();
                }
            }
        )::asList
    );
}

@yegor256
Copy link
Member

@maxonfjvipon the easiest fix would be to make StrictXmir#validate synchronized.

@maxonfjvipon
Copy link
Member

@yegor256 yes, it works

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Dec 19, 2024

@maxonfjvipon the easiest fix would be to make StrictXmir#validate synchronized

@yegor256 @maxonfjvipon Please, don't do this. This will significantly decrease the performance of jeo-maven-plugin

@yegor256
Copy link
Member

@maxonfjvipon a more fine-grained solution would be to make StrictXmir#download synchronized. This is the best we can do, I believe.

@maxonfjvipon
Copy link
Member

@yegor256 yes, I understand, I'll try

yegor256 added a commit that referenced this issue Dec 20, 2024
…ther

bug(#3684): Added synchronization in StrictXmir
@yegor256
Copy link
Member

@rultor release, tag is 0.49.2

@rultor
Copy link
Contributor

rultor commented Dec 20, 2024

@rultor release, tag is 0.49.2

@yegor256 OK, I will release it now. Please check the progress here.

@rultor
Copy link
Contributor

rultor commented Dec 20, 2024

@rultor release, tag is 0.49.2

@yegor256 Done! FYI, the full log is here (took me 16min).

@yegor256
Copy link
Member

@volodya-lombrozo try 0.49.2 please

@volodya-lombrozo
Copy link
Member Author

@yegor256 This issue is gone. Thank you. However, we have another one: #3726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants