Skip to content

Commit

Permalink
o fix JENKINS-10377: not specifying a regex leads to a NPE.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.jenkins-ci.org/trunk/hudson/plugins/thinBackup@39650 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information
msteinkogler committed Jul 19, 2011
1 parent a336f03 commit 370ac10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -74,8 +74,9 @@ public HudsonBackup(final File backupRoot, final File hudsonHome, final BackupTy
this.moveOldBackupsToZipFile = moveOldBackupsToZipFile;
this.nrMaxStoredFull = nrMaxStoredFull;
this.backupBuildResults = backupBuildResults;
final String tmpExpression = (excludedFilesRegex != null) ? excludedFilesRegex : "";
try {
excludedFilesRegexPattern = Pattern.compile(excludedFilesRegex);
excludedFilesRegexPattern = Pattern.compile(tmpExpression);
} catch (final PatternSyntaxException pse) {
LOGGER.log(Level.INFO, "Regex pattern for excluding files is invalid.", pse);
excludedFilesRegexPattern = null;
Expand Down Expand Up @@ -115,8 +116,9 @@ public HudsonBackup(final File backupRoot, final File hudsonHome, final BackupTy
this.moveOldBackupsToZipFile = moveOldBackupsToZipFile;
this.nrMaxStoredFull = nrMaxStoredFull;
this.backupBuildResults = backupBuildResults;
final String tmpExpression = (excludedFilesRegex != null) ? excludedFilesRegex : "";
try {
excludedFilesRegexPattern = Pattern.compile(excludedFilesRegex);
excludedFilesRegexPattern = Pattern.compile(tmpExpression);
} catch (final PatternSyntaxException pse) {
pse.printStackTrace();
excludedFilesRegexPattern = null;
Expand Down
Expand Up @@ -121,4 +121,18 @@ public void testHudsonDiffBackup() throws Exception {
Assert.assertEquals(1, lastDiffBackup.list().length);
}

@Test
public void testNullFileExclusionRegexTestConstructor() {
final Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE - 10));
final HudsonBackup backup = new HudsonBackup(backupDir, root, BackupType.FULL, -1, false, false, true, cal.getTime(), null);
Assert.assertNotNull(backup);
}

@Test
public void testNullFileExclusionRegex() {
final HudsonBackup backup = new HudsonBackup(backupDir, root, BackupType.FULL, -1, false, false, true, null);
Assert.assertNotNull(backup);
}

}

0 comments on commit 370ac10

Please sign in to comment.