Fixed FELIX-4572 : Web Console may cause NPE on refresh packages
https://issues.apache.org/jira/browse/FELIX-4572
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1612488 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 0695e6e..f4a7a1e 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -414,16 +414,29 @@
// we ignore this
}
+ if ( getBundleContext() == null ) {
+ System.out.println("BundlesServlet.doPost()1");
+ return;
+ }
+
// write the state only
resp.setContentType( "application/json" ); //$NON-NLS-1$
resp.setCharacterEncoding( "UTF-8" ); //$NON-NLS-1$
- resp.getWriter().print( "{\"fragment\":" + isFragmentBundle( bundle ) // //$NON-NLS-1$
- + ",\"stateRaw\":" + bundle.getState() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
+ if ( null == getBundleContext() )
+ {
+ // refresh package on the web console itself or some of it's dependencies
+ resp.getWriter().print("false"); //$NON-NLS-1$
+ }
+ else
+ {
+ resp.getWriter().print( "{\"fragment\":" + isFragmentBundle( bundle ) //$NON-NLS-1$
+ + ",\"stateRaw\":" + bundle.getState() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
return;
}
}
- if ( success )
+ if ( success && null != getBundleContext() )
{
// let's wait a little bit to give the framework time
// to process our request
@@ -448,7 +461,7 @@
super.doPost( req, resp );
}
}
-
+
private String getServicesRoot(HttpServletRequest request)
{
return ( ( String ) request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) ) +