mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-07 16:05:34 +02:00
Handle NullPointerException in hgrc clean-up
We encountered NullPointerExceptions during hg repository imports. This happened, when neither authentication nor proxy definions had been given. In this case, no hgrc will be created and therefore we get the exception in the clean-up step. Now, the clean-up is only triggered, if the hgrc had been created beforehand. To prevent further error in the clean-up, we no catch other potential exceptions and log them but do not let them break the import. Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com> Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
2
gradle/changelog/hg_import.yaml
Normal file
2
gradle/changelog/hg_import.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Import of hg repositories without credentials
|
||||
@@ -94,7 +94,13 @@ public class TemporaryConfigFactory {
|
||||
if (!exists && file.exists() && !file.delete()) {
|
||||
LOG.error("failed to delete temporary hgrc {}", file);
|
||||
} else if (exists && file.exists()) {
|
||||
cleanUpHgrc(file);
|
||||
try {
|
||||
if (hgrc != null) {
|
||||
cleanUpHgrc(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("error cleaning up hgrc", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,13 @@ class TemporaryConfigFactoryTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("java:S2699") // test should just ensure that no exception is thrown
|
||||
void shouldNotFailIfFileExistsButWithoutProxyOrAuthentication() throws IOException {
|
||||
Files.createFile(hgrc);
|
||||
configFactory.withContext(commandContext).call(() -> null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateHgrcWithAuthentication() throws IOException {
|
||||
configFactory
|
||||
|
||||
Reference in New Issue
Block a user