Skip to content

Commit 8f9d820

Browse files
chris-camposcopybara-github
authored andcommitted
Fix NullPointerException when no file name is given
This change ensures that Copybara handles cases where the configuration path provided on the command line does not have a filename (e.g., the root directory '/'), preventing a `java.lang.NullPointerException` from `Path.getFileName().toString()`. BUG=485259576 GWSQ_IGNORE: chriscampos@google.com PiperOrigin-RevId: 883360034 Change-Id: I5c413e51943b572029aef9b72d4679400a8a9dfe
1 parent 27ded66 commit 8f9d820

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

java/com/google/copybara/Main.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,13 @@ protected ContextProvider newInfoContextProvider() {
414414
protected Path validateLocalConfig(GeneralOptions generalOptions, String configLocation)
415415
throws ValidationException {
416416
Path configPath = generalOptions.getFileSystem().getPath(configLocation).normalize();
417-
String fileName = configPath.getFileName().toString();
417+
Path fileName = configPath.getFileName();
418+
checkCondition(fileName != null, "The configuration path '%s' is not a file.", configPath);
418419
checkCondition(
419-
fileName.contentEquals(COPYBARA_SKYLARK_CONFIG_FILENAME),
420+
fileName.toString().contentEquals(COPYBARA_SKYLARK_CONFIG_FILENAME),
420421
"Copybara config file filename should be '%s' but it is '%s'.",
421-
COPYBARA_SKYLARK_CONFIG_FILENAME, configPath.getFileName());
422+
COPYBARA_SKYLARK_CONFIG_FILENAME,
423+
fileName);
422424

423425
// Treat the top level element specially since it is passed thru the command line.
424426
if (!Files.exists(configPath)) {

0 commit comments

Comments
 (0)