]> source.dussan.org Git - archiva.git/commitdiff
Fixing NPEs
authorMartin Stockhammer <martin_s@apache.org>
Sat, 3 Jul 2021 09:20:04 +0000 (11:20 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sat, 3 Jul 2021 09:20:04 +0000 (11:20 +0200)
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java

index ebdd0c7612da064b0ae42dcbf7925af087fb065a..81e6377b237879787b2c1f14e9eb864746939a3d 100644 (file)
@@ -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
         }