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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <constantine.plotnikov@xxxxxxxxx>
---
 .../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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]