From bc27b2584b5a1500cb74419a1a98a02acb4dff4d Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 3 Jul 2021 11:20:04 +0200 Subject: [PATCH] Fixing NPEs --- .../admin/mock/MavenIndexContextMock.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java index ebdd0c761..81e6377b2 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java @@ -47,12 +47,17 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { MavenIndexContextMock(Repository repository, IndexingContext delegate) { this.delegate = delegate; this.repository = repository; - try { - this.filesystemStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath(), new DefaultFileLockManager()); - } catch (IOException e) { - e.printStackTrace(); + if(delegate!=null && delegate.getIndexDirectoryFile()!=null) + { + try + { + this.filesystemStorage = new FilesystemStorage( delegate.getIndexDirectoryFile( ).toPath( ), new DefaultFileLockManager( ) ); + } + catch ( IOException e ) + { + e.printStackTrace( ); + } } - } @Override @@ -95,7 +100,7 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { public void close(boolean deleteFiles) throws IOException { open = false; try { - delegate.close(deleteFiles); + if (delegate!=null) delegate.close(deleteFiles); } catch (NoSuchFileException e) { // Ignore missing directory } @@ -105,7 +110,7 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { public void close() throws IOException { open = false; try { - delegate.close(false); + if (delegate!=null) delegate.close(false); } catch (NoSuchFileException e) { // Ignore missing directory } -- 2.39.5