SLING-2702 : NPE as repository class loader might not have been instantiated
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1426226 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java b/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java
index c7774d0..b39346a 100644
--- a/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java
+++ b/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java
@@ -211,7 +211,7 @@
return this.repository != null;
}
- private synchronized ClassLoader getOrCreateClassLoader() {
+ private synchronized RepositoryClassLoader getOrCreateClassLoader() {
if ( this.repositoryClassLoader == null || !this.repositoryClassLoader.isLive() ) {
// make sure to cleanup any existing class loader
@@ -243,7 +243,7 @@
Item fileItem = session.getItem(path);
fileItem.remove();
session.save();
- this.repositoryClassLoader.handleEvent(path);
+ this.getOrCreateClassLoader().handleEvent(path);
return true;
}
} catch (final RepositoryException re) {
@@ -278,8 +278,8 @@
session = this.createSession();
session.move(oldPath, newPath);
session.save();
- this.repositoryClassLoader.handleEvent(oldName);
- this.repositoryClassLoader.handleEvent(newName);
+ this.getOrCreateClassLoader().handleEvent(oldName);
+ this.getOrCreateClassLoader().handleEvent(newName);
return true;
} catch (final RepositoryException re) {
logger.error("Cannot rename " + oldName + " to " + newName, re);
@@ -390,6 +390,7 @@
/**
* @see java.io.ByteArrayOutputStream#close()
*/
+ @Override
public void close() throws IOException {
super.close();
@@ -464,7 +465,7 @@
contentNode.setProperty("jcr:mimeType", mimeType);
session.save();
- this.repositoryOutputProvider.repositoryClassLoader.handleEvent(fileName);
+ this.repositoryOutputProvider.getOrCreateClassLoader().handleEvent(fileName);
} catch (final RepositoryException re) {
throw (IOException)new IOException("Cannot write file " + fileName + ", reason: " + re.toString()).initCause(re);
} finally {