diff options
author | Olivier Lamy <olamy@apache.org> | 2013-02-07 14:03:07 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-02-07 14:03:07 +0000 |
commit | 9ff7c3333284e8ae7c07209b0ac2f4685bdf3891 (patch) | |
tree | f3f6d9cfd6ad4733375021cbd4724bc9df7c1b34 | |
parent | 9c07475c30e847196670b3561e60f6e9cbcd6cff (diff) | |
download | archiva-9ff7c3333284e8ae7c07209b0ac2f4685bdf3891.tar.gz archiva-9ff7c3333284e8ae7c07209b0ac2f4685bdf3891.zip |
fix possible NPE when restarting a tomcat with serialized session
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1443484 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java index 8dff3d13b..e0ffaad68 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java @@ -50,11 +50,18 @@ public class TemporaryGroupIndexSessionCleaner public void sessionCreated( HttpSessionEvent httpSessionEvent ) { // ensure the map is here to avoid NPE - httpSessionEvent.getSession().setAttribute( TEMPORARY_INDEX_SESSION_KEY, - new HashMap<String, TemporaryGroupIndex>() ); - WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext( - httpSessionEvent.getSession().getServletContext() ); - indexMerger = webApplicationContext.getBean( IndexMerger.class ); + if ( httpSessionEvent.getSession().getAttribute( TEMPORARY_INDEX_SESSION_KEY ) == null ) + { + httpSessionEvent.getSession().setAttribute( TEMPORARY_INDEX_SESSION_KEY, + new HashMap<String, TemporaryGroupIndex>() ); + } + + if ( indexMerger == null ) + { + WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext( + httpSessionEvent.getSession().getServletContext() ); + indexMerger = webApplicationContext.getBean( IndexMerger.class ); + } } public void sessionDestroyed( HttpSessionEvent httpSessionEvent ) @@ -67,8 +74,19 @@ public class TemporaryGroupIndexSessionCleaner { log.info( "cleanup temporaryGroupIndex {} directory {}", temporaryGroupIndex.getIndexId(), temporaryGroupIndex.getDirectory().getAbsolutePath() ); - indexMerger.cleanTemporaryGroupIndex( temporaryGroupIndex ); + getIndexMerger( httpSessionEvent ).cleanTemporaryGroupIndex( temporaryGroupIndex ); + } + } + + private IndexMerger getIndexMerger( HttpSessionEvent httpSessionEvent ) + { + if ( indexMerger == null ) + { + WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext( + httpSessionEvent.getSession().getServletContext() ); + indexMerger = webApplicationContext.getBean( IndexMerger.class ); } + return indexMerger; } } |