Skip to content

Commit

Permalink
Fix processing report files with Unicode paths (#58)
Browse files Browse the repository at this point in the history
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 processes 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)
solves the issue due to JDK uses passed InputStream and all
described here above do not affect us.
  • Loading branch information
Aleksey Svistunov authored Jun 15, 2022
1 parent 24ee7d0 commit 16a0199
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.io.UncheckedIOException;

/**
* Cloc report parser and the parsed file.
Expand Down Expand Up @@ -72,7 +76,14 @@ public static ClocReport parse(File file) throws JAXBException {
currentThread.setContextClassLoader(initialClassLoader);
}
Unmarshaller unmarshaller = context.createUnmarshaller();
return (ClocReport) unmarshaller.unmarshal(file);
// Jenkins replaces ASCII symbols like colons found in filenames to Unicode.
// Using File() here causes converting Unicode symbols back to ASCII.
// Such files could not be found of course.
try (InputStream is = new FileInputStream(file)) {
return (ClocReport) unmarshaller.unmarshal(is);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

/**
Expand Down

0 comments on commit 16a0199

Please sign in to comment.