aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-07-16 11:20:28 -0700
committerXavier Ducrohet <xav@android.com>2012-07-16 11:20:28 -0700
commit27c58b99171127ff0f38a94926a7ed8488cabbfc (patch)
tree2038a8f3ddbfc6921b3328b0a0c9d295817eb397
parenta24267aa73901dcf6464e69dd071faff1b56b7fa (diff)
downloadsdk-27c58b99171127ff0f38a94926a7ed8488cabbfc.zip
sdk-27c58b99171127ff0f38a94926a7ed8488cabbfc.tar.gz
sdk-27c58b99171127ff0f38a94926a7ed8488cabbfc.tar.bz2
Fix a possible NPE when reading bad prop files.
Change-Id: I8f650a139c121bd68e3c246ff1a7db1a02378191
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java
index e028aea..27879a7 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java
@@ -22,6 +22,7 @@ import static com.android.sdklib.SdkConstants.FN_ANDROID_PROGUARD_FILE;
import static com.android.sdklib.SdkConstants.FN_PROJECT_PROGUARD_FILE;
import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.io.FolderWrapper;
import com.android.io.IAbstractFile;
import com.android.io.IAbstractFolder;
@@ -423,10 +424,12 @@ public class ProjectProperties implements IPropertySource {
* <p/>If the file is not present, null is returned with no error messages sent to the log.
*
* @param propFile the property file to parse
- * @param log the ISdkLog object receiving warning/error from the parsing. Cannot be null.
+ * @param log the ISdkLog object receiving warning/error from the parsing.
* @return the map of (key,value) pairs, or null if the parsing failed.
*/
- public static Map<String, String> parsePropertyFile(IAbstractFile propFile, ISdkLog log) {
+ public static Map<String, String> parsePropertyFile(
+ @NonNull IAbstractFile propFile,
+ @Nullable ISdkLog log) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(propFile.getContents(),
@@ -435,15 +438,18 @@ public class ProjectProperties implements IPropertySource {
String line = null;
Map<String, String> map = new HashMap<String, String>();
while ((line = reader.readLine()) != null) {
+ line = line.trim();
if (line.length() > 0 && line.charAt(0) != '#') {
Matcher m = PATTERN_PROP.matcher(line);
if (m.matches()) {
map.put(m.group(1), unescape(m.group(2)));
} else {
- log.warning("Error parsing '%1$s': \"%2$s\" is not a valid syntax",
- propFile.getOsLocation(),
- line);
+ if (log != null) {
+ log.warning("Error parsing '%1$s': \"%2$s\" is not a valid syntax",
+ propFile.getOsLocation(),
+ line);
+ }
return null;
}
}
@@ -455,13 +461,17 @@ public class ProjectProperties implements IPropertySource {
// calling the method.
// Return null below.
} catch (IOException e) {
- log.warning("Error parsing '%1$s': %2$s.",
- propFile.getOsLocation(),
- e.getMessage());
+ if (log != null) {
+ log.warning("Error parsing '%1$s': %2$s.",
+ propFile.getOsLocation(),
+ e.getMessage());
+ }
} catch (StreamException e) {
- log.warning("Error parsing '%1$s': %2$s.",
- propFile.getOsLocation(),
- e.getMessage());
+ if (log != null) {
+ log.warning("Error parsing '%1$s': %2$s.",
+ propFile.getOsLocation(),
+ e.getMessage());
+ }
} finally {
if (reader != null) {
try {