From cd3d952ec66fa3de24faecc413398b97aa37dc18 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 9 Jun 2015 15:54:52 -0700 Subject: [PATCH] Revert "Config: Distinguish between empty and null strings" This reverts commit 96eb3ee3976e7e9e3e118851fa614cce8a1f7d88, which broke Gerrit tests that set a config value to 'null', serialize the result, deserialize, and expect 'null' from Config.getString[1]. The intent of that commit was to make it possible to distinguish between an absent and an empty config value, which we'll have to do with a new method. Revert the behavior change. Keep the tests from 428cb23f2de8, since they test the behavior more precisely than the old tests did. [1] https://gerrit-review.googlesource.com/68452 Change-Id: Ie8042f380ea0e34e3203e1991aa0feb2e6e44641 Signed-off-by: Jonathan Nieder --- .../tst/org/eclipse/jgit/lib/ConfigTest.java | 12 ++++++++---- .../src/org/eclipse/jgit/lib/Config.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index b90a0c4671..6238a354d8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -707,8 +707,8 @@ public class ConfigTest { assertEquals("0", c.getString("a", null, "x")); assertEquals(0, c.getInt("a", null, "x", 1)); - assertEquals("", c.getString("a", null, "y")); - assertArrayEquals(new String[]{""}, c.getStringList("a", null, "y")); + assertNull(c.getString("a", null, "y")); + assertArrayEquals(new String[]{null}, c.getStringList("a", null, "y")); try { c.getInt("a", null, "y", 1); } catch (IllegalArgumentException e) { @@ -730,9 +730,13 @@ public class ConfigTest { public void testEmptyValueAtEof() throws Exception { String text = "[a]\nx ="; Config c = parse(text); - assertEquals("", c.getString("a", null, "x")); + assertNull(c.getString("a", null, "x")); + assertArrayEquals(new String[]{null}, + c.getStringList("a", null, "x")); c = parse(text + "\n"); - assertEquals("", c.getString("a", null, "x")); + assertNull(c.getString("a", null, "x")); + assertArrayEquals(new String[]{null}, + c.getStringList("a", null, "x")); } private static void assertReadLong(long exp) throws ConfigInvalidException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 16953bb340..e48386d024 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -1266,7 +1266,7 @@ public class Config { value.append((char) c); } - return value.toString(); + return value.length() > 0 ? value.toString() : null; } /** -- 2.39.5