Subject: [JGIT PATCH 2/3] Config.getSubsections(...) now loads the file if it has not been loaded

From: Constantine Plotnikov <[email-masked]>
Date: Wed, 24 Jun 2009 21:48:04 +0400

If method getSubsections() is invoked before any entry in the config
file is accessed via get*(section, subsection, name) methods,
NPE is thrown because file is not yet loaded. This patch fixes the
problem by ensuring that file is loaded before iterating entries
in this method.

Signed-off-by: Constantine Plotnikov <[email-masked]>
---
 .../src/org/spearce/jgit/lib/Config.java           |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
index 62daef3..4220c37 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
@@ -367,6 +367,7 @@ public String getString(final String section, String subsection,
 	 */
 	public Set<String> getSubsections(final String section) {
 		final Set<String> result = new HashSet<String>();
+		ensureLoaded();
 
 		for (final Entry e : entries) {
 			if (section.equalsIgnoreCase(e.base) && e.extendedBase != null)
@@ -401,8 +402,7 @@ private String getRawString(final String section, final String subsection,
 			return null;
 	}
 
-	private Object getRawEntry(final String section, final String subsection,
-			final String name) {
+	private void ensureLoaded() {
 		if (!readFile) {
 			try {
 				load();
@@ -413,6 +413,11 @@ private Object getRawEntry(final String section, final String subsection,
 				err.printStackTrace();
 			}
 		}
+	}
+
+	private Object getRawEntry(final String section, final String subsection,
+			final String name) {
+		ensureLoaded();
 
 		String ss;
 		if (subsection != null)
-- 
1.6.1.2