]> source.dussan.org Git - jgit.git/commitdiff
[errorprone] BaseRepositoryBuilder: Use #split(sep, limit) 75/1203475/1
authorIvan Frade <ifrade@google.com>
Thu, 31 Oct 2024 19:50:00 +0000 (12:50 -0700)
committerIvan Frade <ifrade@google.com>
Fri, 1 Nov 2024 22:42:01 +0000 (15:42 -0700)
String.split(String) and Pattern.split(CharSequence) have surprising
behaviour [1].

We use one of the recommended replacements: #split(sep, limit).

[1] https://errorprone.info/bugpattern/StringSplitter

Change-Id: Ie1cf7590bd8660d21c79c5c3c1bc2765e5d9462b

org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java

index d232be6276734ab9c24ae9baf734691e53d7967a..0c1da83dfbc3a82753880aea2db12fc2a58e2d14 100644 (file)
@@ -15,6 +15,7 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_BARE;
 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WORKTREE;
 import static org.eclipse.jgit.lib.Constants.CONFIG;
 import static org.eclipse.jgit.lib.Constants.DOT_GIT;
+import static org.eclipse.jgit.lib.Constants.GITDIR_FILE;
 import static org.eclipse.jgit.lib.Constants.GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY;
 import static org.eclipse.jgit.lib.Constants.GIT_CEILING_DIRECTORIES_KEY;
 import static org.eclipse.jgit.lib.Constants.GIT_COMMON_DIR_KEY;
@@ -23,7 +24,6 @@ import static org.eclipse.jgit.lib.Constants.GIT_INDEX_FILE_KEY;
 import static org.eclipse.jgit.lib.Constants.GIT_OBJECT_DIRECTORY_KEY;
 import static org.eclipse.jgit.lib.Constants.GIT_WORK_TREE_KEY;
 import static org.eclipse.jgit.lib.Constants.OBJECTS;
-import static org.eclipse.jgit.lib.Constants.GITDIR_FILE;
 
 import java.io.File;
 import java.io.IOException;
@@ -485,7 +485,7 @@ public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Re
                if (getAlternateObjectDirectories() == null) {
                        String val = sr.getenv(GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY);
                        if (val != null) {
-                               for (String path : val.split(File.pathSeparator))
+                               for (String path : val.split(File.pathSeparator, -1))
                                        addAlternateObjectDirectory(new File(path));
                        }
                }
@@ -505,7 +505,7 @@ public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Re
                if (ceilingDirectories == null) {
                        String val = sr.getenv(GIT_CEILING_DIRECTORIES_KEY);
                        if (val != null) {
-                               for (String path : val.split(File.pathSeparator))
+                               for (String path : val.split(File.pathSeparator, -1))
                                        addCeilingDirectory(new File(path));
                        }
                }