From ab22d11279db912f1b69a48b0fa676972b189aea Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 15 Oct 2015 12:04:03 +0100 Subject: coverity#1326731 Dm: Dubious method used and coverity#1326732 Dm: Dubious method used coverity#1326734 Dm: Dubious method used coverity#1326735 Dm: Dubious method used coverity#1326739 Dm: Dubious method used Change-Id: Id9d39decf7442b503079ebcfe8c881f0f2fe3eb3 --- .../sun/star/comp/beans/LocalOfficeConnection.java | 7 ++- .../com/sun/star/comp/helper/Bootstrap.java | 8 ++- .../sun/star/lib/loader/InstallationFinder.java | 70 ++++++++++++---------- qadevOOo/runner/helper/APIDescGetter.java | 6 +- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/bean/com/sun/star/comp/beans/LocalOfficeConnection.java b/bean/com/sun/star/comp/beans/LocalOfficeConnection.java index 70d51dfd497e..d58a30fe23f6 100644 --- a/bean/com/sun/star/comp/beans/LocalOfficeConnection.java +++ b/bean/com/sun/star/comp/beans/LocalOfficeConnection.java @@ -755,9 +755,10 @@ public class LocalOfficeConnection @Override public void run() { - java.io.BufferedReader r = new java.io.BufferedReader( - new java.io.InputStreamReader(m_in) ); try { + java.io.BufferedReader r = new java.io.BufferedReader( + new java.io.InputStreamReader(m_in, "UTF-8") ); + for ( ; ; ) { String s = r.readLine(); if ( s == null ) { @@ -765,6 +766,8 @@ public class LocalOfficeConnection } m_print.println(s); } + } catch ( UnsupportedEncodingException e ) { + e.printStackTrace( System.err ); } catch ( java.io.IOException e ) { e.printStackTrace( System.err ); } diff --git a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java index 70328ce5ec8c..a36f16c9b25d 100644 --- a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java +++ b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java @@ -38,6 +38,7 @@ import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; @@ -333,9 +334,10 @@ public class Bootstrap { new Thread( "Pipe: " + prefix) { @Override public void run() { - BufferedReader r = new BufferedReader( - new InputStreamReader( in ) ); try { + BufferedReader r = new BufferedReader( + new InputStreamReader(in, "UTF-8") ); + for ( ; ; ) { String s = r.readLine(); if ( s == null ) { @@ -343,6 +345,8 @@ public class Bootstrap { } out.println( prefix + s ); } + } catch ( UnsupportedEncodingException e ) { + e.printStackTrace( System.err ); } catch ( java.io.IOException e ) { e.printStackTrace( System.err ); } diff --git a/odk/source/com/sun/star/lib/loader/InstallationFinder.java b/odk/source/com/sun/star/lib/loader/InstallationFinder.java index d1f8738cbef9..b04b6f819c45 100644 --- a/odk/source/com/sun/star/lib/loader/InstallationFinder.java +++ b/odk/source/com/sun/star/lib/loader/InstallationFinder.java @@ -310,45 +310,53 @@ final class InstallationFinder { StreamGobbler gobbler = new StreamGobbler( proc.getErrorStream() ); gobbler.start(); - // read the which output from standard input stream - BufferedReader br = new BufferedReader( - new InputStreamReader( proc.getInputStream() ) ); - String line = null; try { - while ( ( line = br.readLine() ) != null ) { - if ( path == null ) { - // get the path from the which output - int index = line.lastIndexOf( SOFFICE ); - if ( index != -1 ) { - int end = index + SOFFICE.length(); - for ( int i = 0; i <= index; i++ ) { - File file = new File( line.substring( i, end ) ); - try { - if ( file.exists() ) { - // resolve symlink - path = file.getCanonicalFile().getParent(); - if ( path != null ) - break; + // read the which output from standard input stream + BufferedReader br = new BufferedReader( + new InputStreamReader( proc.getInputStream(), "UTF-8" ) ); + String line = null; + try { + while ( ( line = br.readLine() ) != null ) { + if ( path == null ) { + // get the path from the which output + int index = line.lastIndexOf( SOFFICE ); + if ( index != -1 ) { + int end = index + SOFFICE.length(); + for ( int i = 0; i <= index; i++ ) { + File file = new File( line.substring( i, end ) ); + try { + if ( file.exists() ) { + // resolve symlink + path = file.getCanonicalFile().getParent(); + if ( path != null ) + break; + } + } catch ( SecurityException e ) { + return null; } - } catch ( SecurityException e ) { - return null; } } } } + } catch ( IOException e ) { + // if an I/O exception is thrown, return null + System.err.println( "com.sun.star.lib.loader." + + "InstallationFinder::getPathFromWhich: " + + "reading which command output failed: " + e ); + return null; + } finally { + try { + br.close(); + } catch ( IOException e ) { + // closing standard input stream failed, ignore + } } - } catch ( IOException e ) { - // if an I/O exception is thrown, return null + } catch ( UnsupportedEncodingException e ) { + // if an Encoding exception is thrown, return null System.err.println( "com.sun.star.lib.loader." + "InstallationFinder::getPathFromWhich: " + - "reading which command output failed: " + e ); + "encoding failed: " + e ); return null; - } finally { - try { - br.close(); - } catch ( IOException e ) { - // closing standard input stream failed, ignore - } } try { @@ -563,12 +571,14 @@ final class InstallationFinder { public void run() { try { BufferedReader br = new BufferedReader( - new InputStreamReader( m_istream ) ); + new InputStreamReader( m_istream, "UTF-8" ) ); // read from input stream while ( br.readLine() != null ) { // don't handle line content } br.close(); + } catch (UnsupportedEncodingException e) { + // cannot read from input stream } catch ( IOException e ) { // stop reading from input stream } diff --git a/qadevOOo/runner/helper/APIDescGetter.java b/qadevOOo/runner/helper/APIDescGetter.java index 60304c87c099..55a269889486 100644 --- a/qadevOOo/runner/helper/APIDescGetter.java +++ b/qadevOOo/runner/helper/APIDescGetter.java @@ -580,7 +580,7 @@ public class APIDescGetter extends DescGetter entry.endsWith(sEndsWithCSVName)) { InputStream input = this.getClass().getResourceAsStream("/" + entry); - csvFile = new BufferedReader(new InputStreamReader(input)); + csvFile = new BufferedReader(new InputStreamReader(input, "UTF-8")); break; } } @@ -588,7 +588,7 @@ public class APIDescGetter extends DescGetter else { InputStream in = con.getInputStream(); - java.io.BufferedReader buf = new java.io.BufferedReader(new InputStreamReader(in)); + java.io.BufferedReader buf = new java.io.BufferedReader(new InputStreamReader(in, "UTF-8")); while (true) { String entry = buf.readLine(); @@ -602,7 +602,7 @@ public class APIDescGetter extends DescGetter module + "/" + entry); - csvFile = new BufferedReader(new InputStreamReader(input)); + csvFile = new BufferedReader(new InputStreamReader(input, "UTF-8")); break; } } -- cgit