XmlParser.parse(InputStream) and parse(Reader) leave Bom.getSpecVersion() null
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The bug is in src/main/java/org/cyclonedx/parsers/XmlParser.java: parse(File) and parse(byte[]) call identifySchemaVersion and injectSchemaVersion to set specVersion, while parse(InputStream) and parse(Reader) (around lines 108-125) return MAPPER.readValue(..., Bom.class) directly. Start by reading those four methods and run the Repro snippet from the issue. Done when the stream and reader paths print 1.5 and Bom.equals matches the byte[] result.
Written by the indexing model from the issue text.
Description
Parsing a CycloneDX XML BOM with XmlParser.parse(InputStream) or XmlParser.parse(Reader) leaves Bom.getSpecVersion() as null, whereas XmlParser.parse(byte[]) and XmlParser.parse(File) populate it (for example, "1.5") on the same XML input.
Save pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>repro</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-core-java</artifactId>
<version>13.5.0</version>
</dependency>
</dependencies>
</project>
Save src/main/java/Repro.java:
import org.cyclonedx.model.Bom;
import org.cyclonedx.parsers.XmlParser;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
public class Repro {
public static void main(String[] args) throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<bom xmlns=\"http://cyclonedx.org/schema/bom/1.5\" version=\"1\">"
+ "<components><component type=\"library\"><name>log4j-core</name><version>2.17.0</version></component></components>"
+ "</bom>";
XmlParser parser = new XmlParser();
Bom fromBytes = parser.parse(xml.getBytes(StandardCharsets.UTF_8));
Bom fromStream = parser.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
Bom fromReader = parser.parse(new StringReader(xml));
System.out.println("fromBytes.specVersion=" + fromBytes.getSpecVersion());
System.out.println("fromStream.specVersion=" + fromStream.getSpecVersion());
System.out.println("fromReader.specVersion=" + fromReader.getSpecVersion());
}
}
Run:
mvn -q compile exec:java -Dexec.mainClass=Repro
Actual output:
fromBytes.specVersion=1.5
fromStream.specVersion=null
fromReader.specVersion=null
Expected output: all three calls print 1.5, matching Bom.getSpecVersion() (which documents that specVersion is populated when parsing via Parser and provides no setter) as well as XmlParser.parse(File), XmlParser.parse(byte[]), and JsonParser. Because Bom.equals includes specVersion, fromStream.equals(fromBytes) and fromReader.equals(fromBytes) also evaluate to false.
Tested with cyclonedx-core-java 13.5.0 and master (e591b11c6a).
In src/main/java/org/cyclonedx/parsers/XmlParser.java, parse(File) and parse(byte[]) extract the root namespace version with identifySchemaVersion(...) and set Bom.specVersion via injectSchemaVersion(...), whereas parse(InputStream) and parse(Reader) (lines 108-125) return MAPPER.readValue(..., Bom.class) directly.
Credit: https://ucsbplse.github.io/
- Dominant language
- Java
- Stars
- 124
- Forks
- 97
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CycloneDX/cyclonedx-core-java
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
CycloneDX/cyclonedx-core-java#1002 ·
Maintainers usually reply within 2 days
-
`license-mapping.json` maps classpath-exception license names to the deprecated SPDX id `GPL-2.0-with-classpath-exception`Possibly taken @afalhambra-hivemq claimed this 5 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
CycloneDX/cyclonedx-core-java#998 ·
Maintainers usually reply within 2 days
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
CycloneDX/cyclonedx-core-java#902 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
CycloneDX/cyclonedx-core-java#848 ·
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
CycloneDX/cyclonedx-core-java#838 ·
Maintainers usually reply within 2 days
All issues in CycloneDX/cyclonedx-core-java
Similar issues
-
crash
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON stringPossibly taken @starryeye claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelcontextprotocol/java-sdk#1352 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
account bug course exam iris lecture
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day