From dec7a70e42bd164ee5403fb3c563e87fa803d14b Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 26 Jul 2012 11:37:59 +0000 Subject: [PATCH] NullPointers in property handling --- hsarjcli/src/de/hsadmin/jscli/CASTicket.java | 8 ++++++-- hsarjcli/src/de/hsadmin/jscli/Config.java | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hsarjcli/src/de/hsadmin/jscli/CASTicket.java b/hsarjcli/src/de/hsadmin/jscli/CASTicket.java index e216c3f..c889fd9 100644 --- a/hsarjcli/src/de/hsadmin/jscli/CASTicket.java +++ b/hsarjcli/src/de/hsadmin/jscli/CASTicket.java @@ -117,6 +117,7 @@ public class CASTicket { } private String readFiledGrantingTicket() throws JSCliException { + String filedTicket = null; String userHome = System.getProperty("user.home"); String ticketFileName = userHome + "/.hsadmin.tgt"; File file = new File(ticketFileName); @@ -124,12 +125,15 @@ public class CASTicket { Properties properties = new Properties(); try { properties.load(new FileReader(file)); - return properties.getProperty(user); + filedTicket = properties.getProperty(user); } catch (IOException e) { throw new JSCliException(e); } } - return null; + if (filedTicket == null) { + filedTicket = getGrantingTicket(); + } + return filedTicket; } private void writeFiledGrantingTicket(String ticket) throws JSCliException { diff --git a/hsarjcli/src/de/hsadmin/jscli/Config.java b/hsarjcli/src/de/hsadmin/jscli/Config.java index e5936d9..f082065 100644 --- a/hsarjcli/src/de/hsadmin/jscli/Config.java +++ b/hsarjcli/src/de/hsadmin/jscli/Config.java @@ -43,7 +43,11 @@ public class Config { } public String getProperty(String propertyName) { - return props.getProperty(propertyName).trim(); + String property = props.getProperty(propertyName); + if (property == null) { + return null; + } + return property.trim(); } public String getProperty(String propertyName, String defaultValue) {