From 1b61020d13f47e00448d779f1c3774f46fd1c254 Mon Sep 17 00:00:00 2001 From: svistun Date: Thu, 28 Jan 2021 20:43:54 +0300 Subject: [PATCH] Fix processing report files with Unicode in pathes. Jenkins replaces some ASCII symbols like colons with Unicode storing builds data. Parsing reports letter when users open 'SLOCCount Results' window the plugin unable to retrieve SLOC information - file was stored by path with Unicode. It relates to JDK 8. Using unmarshal(File f) indeed proceses not the File but a URL based on its absolute path. When JDK tries to open connection it calles ParseUtil.decode(url.getFile()) against our path containing Unicode. This method converts Unicode back to ASCII. So we get java.io.FileNotFoundException wrapped in javax.xml.bind.JAXBException, which is ignored by the plugin. Using unmarshal(java.io.InputStream is) soleves the issue due to JDK uses passed InputStream and all described here above do not affect us. --- .../hudson/plugins/sloccount/model/cloc/ClocReport.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/plugins/sloccount/model/cloc/ClocReport.java b/src/main/java/hudson/plugins/sloccount/model/cloc/ClocReport.java index 033f7a9..d180c79 100644 --- a/src/main/java/hudson/plugins/sloccount/model/cloc/ClocReport.java +++ b/src/main/java/hudson/plugins/sloccount/model/cloc/ClocReport.java @@ -11,6 +11,7 @@ import javax.xml.bind.annotation.XmlRootElement; import java.io.File; import java.io.Serializable; +import java.net.URL; /** * Cloc report parser and the parsed file. @@ -61,10 +62,13 @@ public ClocFiles getFiles() { * @return the content of the parsed file in form of a report * @throws javax.xml.bind.JAXBException if a XML related error occurs */ - public static ClocReport parse(File file) throws JAXBException { + public static ClocReport parse(File file) throws JAXBException, java.io.IOException { JAXBContext context = JAXBContext.newInstance(ClocReport.class); Unmarshaller unmarshaller = context.createUnmarshaller(); - return (ClocReport) unmarshaller.unmarshal(file); + // Jenkins replaces ASCII symbols like : to Unicode in filenames. + // Using File() here couse converting Unicode symbols back to ASCII. + // Such files could not be found of course. + return (ClocReport) unmarshaller.unmarshal(new java.io.FileInputStream(file)); } /**