git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
CPConstantine Plotnikov <constantine.plotnikov@gmail.com>
Date
Jun 24, 2009, 17:48 UTC
Message-ID
<1245865685-1288-3-git-send-email-constantine.plotnikov@gmail.com>
In-Reply-To
<1245865685-1288-2-git-send-email-constantine.plotnikov@gmail.com>

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@gmail.com>
---
 .../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
Previous: Constantine PlotnikovNext: Constantine Plotnikov
Message 3 of 5 in “Support for loading .gitmodules from blobs”
  1. 0/3 Support for loading .gitmodules from blobsConstantine Plotnikov, Jun 24, 2009
  2. 1/3 Extracted functionality independent from .git/config from RepositoryConfigConstantine Plotnikov, Jun 24, 2009
  3. 2/3 Config.getSubsections(...) now loads the file if it has not been loadedConstantine Plotnikov, Jun 24, 2009
  4. 3/3 Added BlobBasedConfig that allows accessing configuration files stored in the blobsConstantine Plotnikov, Jun 24, 2009
  5. Shawn O. PearceJun 25, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.