# HG changeset patch # User Severin Gehwolf # Date 1400866107 -7200 # Node ID 64670571181d14d90b9ae38bdda42672f1ca7f40 # Parent 9a8d79ed284488772a30c4bdcb16e5e66bf1ce54 agent.auth file fails to parse if NO new line at EOF. Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-May/009862.html PR1789 diff -r 9a8d79ed2844 -r 64670571181d agent/core/src/main/java/com/redhat/thermostat/agent/config/AgentStorageCredentials.java --- a/agent/core/src/main/java/com/redhat/thermostat/agent/config/AgentStorageCredentials.java Thu May 22 19:08:03 2014 -0600 +++ b/agent/core/src/main/java/com/redhat/thermostat/agent/config/AgentStorageCredentials.java Fri May 23 19:28:27 2014 +0200 @@ -277,7 +277,10 @@ } private int positionOf(char character, char[] data, int start, int end) { - int position = -1; + // Corner case. No new line at EOF. In that case the base case is + // to set the returned position to the full length of the data + // otherwise we get a short array copy in getValue(). + int position = end; for (int possible = start; possible < data.length && possible <= end; possible++) { if (data[possible] == character) { position = possible; diff -r 9a8d79ed2844 -r 64670571181d agent/core/src/test/java/com/redhat/thermostat/agent/config/AgentStorageCredentialsTest.java --- a/agent/core/src/test/java/com/redhat/thermostat/agent/config/AgentStorageCredentialsTest.java Thu May 22 19:08:03 2014 -0600 +++ b/agent/core/src/test/java/com/redhat/thermostat/agent/config/AgentStorageCredentialsTest.java Fri May 23 19:28:27 2014 +0200 @@ -43,6 +43,15 @@ import org.junit.Test; public class AgentStorageCredentialsTest { + + @Test + public void testAuthConfigNoNewlineAtEOF() { + Reader reader = new StringReader("username=user\npassword=pass"); + AgentStorageCredentials creds = new AgentStorageCredentials(reader); + Assert.assertEquals("user", creds.getUsername()); + Assert.assertEquals(4, creds.getPassword().length); + Assert.assertEquals("pass", new String(creds.getPassword())); + } @Test public void testAuthConfig() {