valerybokov edited a comment on pull request #107: URL: https://github.com/apache/pdfbox/pull/107#issuecomment-808661852
> I won't do the "if (resourceAsStream == null)" removal, we just had a user who set up a part of the project (without the resources) and got weird error messages and claimed that our examples weren't working at all. I'll also revert the similar commit already done. > > I see the exception was done at the request of another user: > https://issues.apache.org/jira/browse/PDFBOX-4990 ok. But perhaps you will write a more clear version. You are creating a buffered stream even resource stream is null. You close resource stream and then close buffered stream, but the second stream is wrapper for the first. This way, there is no need to close the resource stream because it will be closed automatically. I know your version of code is shorter and the sonarcloud will be quiet but we write code for programmers not for sonarcloud. Maybe the sonarcloud will find not closed resources (it will be wrong clause) but I'm suggesting this template for all plases (version for Standard14Fonts.loadMetrics): private static void loadMetrics(String fontName) throws IOException { String resourceName = "/org/apache/pdfbox/resources/afm/" + fontName + ".afm"; InputStream resourceAsStream = PDType1Font.class.getResourceAsStream(resourceName); if (resourceAsStream == null) { throw new IOException("resource '" + resourceName + "' not found"); } try(InputStream afmStream = new BufferedInputStream(resourceAsStream)) { AFMParser parser = new AFMParser(afmStream); FontMetrics metric = parser.parse(true); FONTS.put(fontName, metric); } } -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
