From e9dd10476adcdd16263c2d407b8d987a6ae69bbe Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 10 Jan 2013 15:30:45 +0100 Subject: [PATCH] IDEA-98514 (CVS: ITE at sun.reflect.NativeMethodAccessorImpl.invoke0) --- .../pserver/PServerLoginProviderImpl.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/pserver/PServerLoginProviderImpl.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/pserver/PServerLoginProviderImpl.java index 928204bf7bd0..4b0283d61bb8 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/pserver/PServerLoginProviderImpl.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/pserver/PServerLoginProviderImpl.java @@ -75,7 +75,7 @@ public class PServerLoginProviderImpl extends PServerLoginProvider { } private void tryConnection() throws AuthenticationException { - IConnection connection = mySettings.createConnection(new ReadWriteStatistics()); + final IConnection connection = mySettings.createConnection(new ReadWriteStatistics()); try { connection.open(new StreamLogger()); mySettings.setOffline(false); @@ -119,10 +119,11 @@ public class PServerLoginProviderImpl extends PServerLoginProvider { // TODO do release password ! when opening a connection and there's a problem with authorization private static void removeAllPasswordsForThisCvsRootFromPasswordFile(String cvsRoot) throws IOException { - File passFile = getPassFile(); - if (!passFile.isFile()) return; - - List lines = CvsFileUtil.readLinesFrom(passFile, cvsRoot); + final File passFile = getPassFile(); + if (!passFile.isFile()) { + return; + } + final List lines = CvsFileUtil.readLinesFrom(passFile, cvsRoot); try { CvsFileUtil.storeLines(lines, passFile); } @@ -132,18 +133,18 @@ public class PServerLoginProviderImpl extends PServerLoginProvider { } private static void storePassword(String stringConfiguration, String scrambledPassword) throws IOException { - File passFile = getPassFile(); + final File passFile = getPassFile(); FileUtil.createIfDoesntExist(passFile); - List lines = CvsFileUtil.readLinesFrom(passFile); + final List lines = CvsFileUtil.readLinesFrom(passFile); lines.add(stringConfiguration + " " + scrambledPassword); CvsFileUtil.storeLines(lines, passFile); } @Nullable private static String getPassword(String config) { - File passFile = getPassFile(); + final File passFile = getPassFile(); try { - BufferedReader reader = + final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(passFile), CvsApplicationLevelConfiguration.getCharset())); try { return findPasswordIn(reader, config); @@ -165,11 +166,15 @@ public class PServerLoginProviderImpl extends PServerLoginProvider { private static String findPasswordIn(BufferedReader reader, String config) throws IOException { String line; while ((line = reader.readLine()) != null) { - int position = line.indexOf(config); - if (position != -1) { - String result = line.substring(position + config.length()); - return result.substring(1); + final int position = line.indexOf(config); + if (position == -1) { + continue; } + final String result = line.substring(position + config.length()); + if (result.isEmpty()) { + continue; + } + return result.substring(1); } return null; }