jQAssistant / jqassistant

Your Software. Your Structures. Your Rules.
https://jqassistant.org/
GNU General Public License v3.0
197 stars 35 forks source link

Unable to scan Java EE jar with empty beans.xml #354

Closed romixch closed 8 years ago

romixch commented 8 years ago

I tried to scan a nexus repository, which failed at following point:

[main] WARN com.buschmais.jqassistant.plugin.xml.impl.scanner.XmlSourceScannerPlugin - Cannot parse document '/META-INF/beans.xml': ParseError at [row,col]:[1,1]
Message: Premature end of file.
[main] WARN com.buschmais.jqassistant.core.scanner.impl.ScannerImpl - Cannot scan item /META-INF/beans.xml
java.io.IOException: Cannot unmarshal XML document.
        at com.buschmais.jqassistant.plugin.xml.api.scanner.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:83)
        at com.buschmais.jqassistant.plugin.xml.api.scanner.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:72)
        at com.buschmais.jqassistant.plugin.cdi.impl.scanner.BeansXmlScannerPlugin.scan(BeansXmlScannerPlugin.java:44)
        at com.buschmais.jqassistant.plugin.cdi.impl.scanner.BeansXmlScannerPlugin.scan(BeansXmlScannerPlugin.java:26)
        at com.buschmais.jqassistant.plugin.xml.api.scanner.AbstractXmlFileScannerPlugin.scan(AbstractXmlFileScannerPlugin.java:51)
        at com.buschmais.jqassistant.plugin.xml.api.scanner.AbstractXmlFileScannerPlugin.scan(AbstractXmlFileScannerPlugin.java:26)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:51)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:29)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:52)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:23)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:51)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:29)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:52)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:23)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.FileScannerPlugin.scan(FileScannerPlugin.java:34)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.FileScannerPlugin.scan(FileScannerPlugin.java:20)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin.resolveAndScan(MavenArtifactScannerPlugin.java:144)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin.scan(MavenArtifactScannerPlugin.java:86)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin.scan(MavenArtifactScannerPlugin.java:42)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin.scan(MavenRepositoryScannerPlugin.java:105)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin.scan(MavenRepositoryScannerPlugin.java:76)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin.scan(MavenRepositoryScannerPlugin.java:26)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.DefaultUriScannerPlugin.scan(DefaultUriScannerPlugin.java:45)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.DefaultUriScannerPlugin.scan(DefaultUriScannerPlugin.java:20)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        at com.buschmais.jqassistant.scm.cli.task.ScanTask.scan(ScanTask.java:127)
        at com.buschmais.jqassistant.scm.cli.task.ScanTask.executeTask(ScanTask.java:81)
        at com.buschmais.jqassistant.scm.cli.task.AbstractTask.run(AbstractTask.java:61)
        at com.buschmais.jqassistant.scm.cli.Main.executeTask(Main.java:238)
        at com.buschmais.jqassistant.scm.cli.Main.interpretCommandLine(Main.java:190)
        at com.buschmais.jqassistant.scm.cli.Main.run(Main.java:76)
        at com.buschmais.jqassistant.scm.cli.Main.main(Main.java:47)
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.]
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:485)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:417)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:394)
        at com.buschmais.jqassistant.plugin.xml.api.scanner.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:81)
        ... 39 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.
        at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
        at javax.xml.stream.util.StreamReaderDelegate.next(Unknown Source)
        at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:164)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:415)
        ... 41 more
[main] WARN com.buschmais.jqassistant.plugin.xml.api.scanner.XMLFileFilter - Cannot parse XML file '/META-INF/beans.xml'.
Exception in thread "main" java.lang.IllegalStateException: Unexpected problem while scanning: item='http://mynexus:18081/nexus/content/repositories/releases/', path='http://mynexus:18081/nexus/content/repositories/releases/', scope='REPOSITORY', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.DefaultUriScannerPlugin@48bb08aa]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.scm.cli.task.ScanTask.scan(ScanTask.java:127)
        at com.buschmais.jqassistant.scm.cli.task.ScanTask.executeTask(ScanTask.java:81)
        at com.buschmais.jqassistant.scm.cli.task.AbstractTask.run(AbstractTask.java:61)
        at com.buschmais.jqassistant.scm.cli.Main.executeTask(Main.java:238)
        at com.buschmais.jqassistant.scm.cli.Main.interpretCommandLine(Main.java:190)
        at com.buschmais.jqassistant.scm.cli.Main.run(Main.java:76)
        at com.buschmais.jqassistant.scm.cli.Main.main(Main.java:47)
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='http://mynexus:18081/nexus/content/repositories/releases/', path='http://mynexus:18081/nexus/content/repositories/releases/', scope='REPOSITORY', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.UrlScannerPlugin@4ff1ee62, com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin@364eeb6b]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.DefaultUriScannerPlugin.scan(DefaultUriScannerPlugin.java:45)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.DefaultUriScannerPlugin.scan(DefaultUriScannerPlugin.java:20)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 7 more
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='ch.romixch.project.edossier.de:edossier-dokument-install:0.2.6:null:war', path='ch.romixch.project.edossier.de:edossier-dokument-install:0.2.6:null:war', scope='REPOSITORY', pipeline='[com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin@67839514]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin.scan(MavenRepositoryScannerPlugin.java:105)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin.scan(MavenRepositoryScannerPlugin.java:76)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenRepositoryScannerPlugin.scan(MavenRepositoryScannerPlugin.java:26)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 10 more
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='d:\daten\jqassistant\jqassistant.distribution-1.1.2\.\jqassistant\data\m2repo\aaddff8ae786d1f390bbab4dd2b7002e\ch\romixch\project\edossier\de\edossier-dokument-install\0.2.6\edossier-dokument-install-0.2.6.war', path='d:\daten\jqassistant\jqassistant.distribution-1.1.2\.\jqassistant\data\m2repo\aaddff8ae786d1f390bbab4dd2b7002e\ch\romixch\project\edossier\de\edossier-dokument-install\0.2.6\edossier-dokument-install-0.2.6.war', scope='null', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.FileScannerPlugin@50a892fb]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin.resolveAndScan(MavenArtifactScannerPlugin.java:144)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin.scan(MavenArtifactScannerPlugin.java:86)
        at com.buschmais.jqassistant.plugin.m2repo.impl.scanner.MavenArtifactScannerPlugin.scan(MavenArtifactScannerPlugin.java:42)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 14 more
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='d:\daten\jqassistant\jqassistant.distribution-1.1.2\.\jqassistant\data\m2repo\aaddff8ae786d1f390bbab4dd2b7002e\ch\romixch\project\edossier\de\edossier-dokument-install\0.2.6\edossier-dokument-install-0.2.6.war', path='d:/daten/jqassistant/jqassistant.distribution-1.1.2/./jqassistant/data/m2repo/aaddff8ae786d1f390bbab4dd2b7002e/ch/romixch/project/edossier/de/edossier-dokument-install/0.2.6/edossier-dokument-install-0.2.6.war', scope='null', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.FileResourceScannerPlugin@1c8bb565, com.buschmais.jqassistant.plugin.javaee6.impl.scanner.WebApplicationArchiveScannerPlugin@180b8b65]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.FileScannerPlugin.scan(FileScannerPlugin.java:34)
        at com.buschmais.jqassistant.plugin.common.impl.scanner.FileScannerPlugin.scan(FileScannerPlugin.java:20)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 18 more
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='d:\daten\jqassistant\jqassistant.distribution-1.1.2\.\jqassistant\data\m2repo\aaddff8ae786d1f390bbab4dd2b7002e\ch\romixch\project\edossier\de\edossier-dokument-install\0.2.6\edossier-dokument-install-0.2.6.war', path='d:/daten/jqassistant/jqassistant.distribution-1.1.2/./jqassistant/data/m2repo/aaddff8ae786d1f390bbab4dd2b7002e/ch/romixch/project/edossier/de/edossier-dokument-install/0.2.6/edossier-dokument-install-0.2.6.war', scope='WAR', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.ZipFileScannerPlugin@93c0bc5]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:52)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:23)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 21 more
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='d:\daten\jqassistant\jqassistant.distribution-1.1.2\.\jqassistant\data\m2repo\aaddff8ae786d1f390bbab4dd2b7002e\ch\romixch\project\edossier\de\edossier-dokument-install\0.2.6\edossier-dokument-install-0.2.6.war!WEB-INF/lib/ch.romixch.itservices.be-ch.romixch.itservicesfunction-interface.jar',
path='/WEB-INF/lib/ch.romixch.itservices.be-ch.romixch.itservicesfunction-interface.jar', scope='WAR', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.FileResourceScannerPlugin@1c8bb565, com.buschmais.jqassistant.plugin.java.impl.scanner.JarScannerPlugin@758774db]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:51)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:29)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 24 more
Caused by: java.lang.IllegalStateException: Unexpected problem while scanning: item='C:\Users\sx9\AppData\Local\Temp\jqassistant-5093780053323803161.tmp', path='/WEB-INF/lib/ch.romixch.itservices.be-ch.romixch.itservicesfunction-interface.jar', scope='CLASSPATH', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.ZipFileScannerPlugin@93c0bc5]'.
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:73)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:52)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractZipArchiveScannerPlugin.scan(AbstractZipArchiveScannerPlugin.java:23)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 27 more
Caused by: java.lang.IllegalArgumentException: Other node is null.
        at org.neo4j.kernel.impl.core.NodeProxy.createRelationshipTo(NodeProxy.java:549)
        at com.buschmais.xo.neo4j.impl.datastore.Neo4jRelationManager.createRelation(Neo4jRelationManager.java:47)
        at com.buschmais.xo.neo4j.impl.datastore.Neo4jRelationManager.createRelation(Neo4jRelationManager.java:20)
        at com.buschmais.xo.impl.EntityPropertyManager.createReference(EntityPropertyManager.java:181)
        at com.buschmais.xo.impl.EntityPropertyManager.createRelation(EntityPropertyManager.java:161)
        at com.buschmais.xo.impl.EntityPropertyManager.createEntityReference(EntityPropertyManager.java:40)
        at com.buschmais.xo.impl.proxy.collection.EntityCollectionProxy.add(EntityCollectionProxy.java:40)
        at com.buschmais.xo.impl.proxy.collection.ListProxy.add(ListProxy.java:78)
        at com.buschmais.jqassistant.plugin.common.api.scanner.ContainerFileResolver.createHierarchy(ContainerFileResolver.java:113)
        at com.buschmais.jqassistant.plugin.common.api.scanner.ContainerFileResolver.flush(ContainerFileResolver.java:54)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:59)
        at com.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:29)
        at com.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:69)
        ... 30 more

It is totally legal to have a completely empty beans.xml according to this tutorial from Oracle: Configuring a CDI Application. Therefore I think this should be fixed. Anyway I think the scanner should be tolerant to broken files in a maven repository. In the worst case it should not read the file, write a warning and go on with the next file.

DirkMahler commented 8 years ago

Agree - the scanner should be robust to handle this case gracefully. Just a question: which jQA version did you use?

romixch commented 8 years ago

Oh. I forgot to mention: I used the latest version 1.1.2. It is a really great tool. Hope to use it much more often.

obfischer commented 8 years ago

Interesting use case. I think it wasn't a good decision to allow empty XML files. But it is as it is.

Handling an empty bean descriptor file is easy if we treat it only as bean descriptor file. But jQAssistant treats the file also a XML document. Here we could have the situation to have an invalid XML document but to have a valid bean descriptor.

According to the XML 1.1 specification a document is well formed (we use also the term valid) if it contains a least one element.

Difficult to handle. In case of an empty file the extension .xml to can not label it as XML document because there is no XML document. And a non-existing XML document is neither well-formed or nor it is not well-formed.

In case of an bean descriptor file with a valid XML document we must label it also with XML because is an XML document.

We must discuss this. There is no just on line solution.

DirkMahler commented 8 years ago

I was also a bit concerned when I first saw that the spec allows empty XML files... (AFAIK this approach has its origin in JBoss Seam where empty property files were used as marker)

I see two options for an empty beans.xml:

  1. Label it as :Beans:Xml:File but with a property xmlWellFormed=false (the property is already defined for Xml labeled nodes)
  2. Just label it as :Beans:File (i.e. without :Xml)

I'd prefer the first option - if a file has the extension .xml and has a defined schema then it should carry that label - even if it's not well-formed nor valid. any opinions on that?

romixch commented 8 years ago

Actually I think there are two issues:

  1. Get the correct information out of a beans.xml
  2. Don't break the wohle scan if some information can't be parsed

For the first issue I think of following solution: Empty beans.xml: Mark as containing a beans descriptor. Don't add any xml specific information beans.xml with valid content: Mark as containing a beans descriptor. Add some xml specific information beans.xml with invalid content: Mark as containing a beans descriptor. Don't add any xml specific information.

For the second issue I think of this: Don't break the whole process if a ScannerPlugin fails to scan a file. This behaviour always leads to trouble. You can be more relaxed if the scan still finishes but some information is missing for a particular broken plugin.

romixch commented 8 years ago

At the end of this month I could help with some pull requests. You can then still reject them :-)

obfischer commented 8 years ago

I would go for option 2. Why? Because there is no XML document and therefore it can't be not well-formed.

DirkMahler commented 8 years ago

@romixch The latest snapshot of the jQA distribution contains a first fix for the empty beans.xml, you can get it from https://oss.sonatype.org/content/repositories/snapshots/com/buschmais/jqassistant/distribution/jqassistant.distribution/1.1.3-SNAPSHOT/ Can you verify if it works for you?

romixch commented 8 years ago

This is great! I will test this as soon as possible. Thanks.

DirkMahler commented 8 years ago

@romixch Just in case that you run into another unexpected issue - you can also trigger the scan with

jqassistant.sh scan maven:repository::http://... -continueOnError

If an error occurs (which I hope this won't be the case) please report it :-)

DirkMahler commented 8 years ago

@romixch We'd like to finish 1.1.3 - is it ok for you if we close this issue?

romixch commented 8 years ago

Yes. I tried it with my repository. It only crashed as I run out of local disk space. Seams to work. Thank you for your work!

DirkMahler commented 8 years ago

Thanks for your feedback and have a nice weekend!