Skip to content

Fix NumberFormatException when creating JSON from llvm-cov 8.x output#1

Open
demirole wants to merge 1 commit intoOlipro:masterfrom
demirole:master
Open

Fix NumberFormatException when creating JSON from llvm-cov 8.x output#1
demirole wants to merge 1 commit intoOlipro:masterfrom
demirole:master

Conversation

@demirole
Copy link

@demirole demirole commented Jun 4, 2020

When creating coverage with llvm-cov 8.0.1, the fields 'hasCount' and
'isRegionEntry' of class 'Segment' are output as booleans as oppose to integers in
previous versions.

This causes a java.lang.NumberFormatException when converting such a
JSON to XML:
Exception in thread "main" java.lang.NumberFormatException: For input string: "true"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:264)
at com.olipro.utils.llvm.LLVMJSONSegment$LLVMJSONSegmentAdapter.deserialize(LLVMJSONSegment.java:22)
at com.olipro.utils.llvm.LLVMJSONSegment$LLVMJSONSegmentAdapter.deserialize(LLVMJSONSegment.java:14)

This commit fixes that error. In addition, it

  • refactors TestLLVMJSON.java to read the test data from file
  • adds a JSON dta file for llvm-cov 8.x output
  • adds a class to provide the gsonBuilder

…8.x output

When creating coverage with llvm-cov 8.0.1, the fields 'hasCount' and
'isRegionEntry' are output as booleans as oppose to integers in
previous versions.

This causes a java.lang.NumberFormatException when converting such a
JSON to XML:
Exception in thread "main" java.lang.NumberFormatException: For input string: "true"
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
    at java.base/java.lang.Integer.parseInt(Integer.java:652)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:264)
    at com.olipro.utils.llvm.LLVMJSONSegment$LLVMJSONSegmentAdapter.deserialize(LLVMJSONSegment.java:22)
    at com.olipro.utils.llvm.LLVMJSONSegment$LLVMJSONSegmentAdapter.deserialize(LLVMJSONSegment.java:14)

This commit fixes that error. In addition, it
- refactors TestLLVMJSON.java to read the test data from file
- adds a JSON dta file for llvm-cov 8.x output
- adds a class to provide the gsonBuilder
@demirole
Copy link
Author

demirole commented Jun 4, 2020

Hi Oliver,
I hope that you don't mind this PR. We are currently updating the whole LLVM toolset from 7 to 8 and stumbled over this issue with the changed output of Segments in JSON.
I should add that I am not a Java developer, so please let me know if this PR is nonsense.
Best, Levent

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

Successfully merging this pull request may close these issues.

1 participant