Skip to content

Commit debe0df

Browse files
Hopefully fix intermittent error on GH Actions builds
1 parent 0dbf7f0 commit debe0df

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

jspwiki-main/src/main/java/org/apache/wiki/ui/admin/DefaultAdminBeanManager.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public class DefaultAdminBeanManager implements WikiEventListener, AdminBeanMana
6666
public DefaultAdminBeanManager( final Engine engine ) {
6767
LOG.info("Using JDK 1.5 Platform MBeanServer");
6868
m_mbeanServer = MBeanServerFactory15.getServer();
69-
7069
m_engine = engine;
7170
applicationName = m_engine.getWikiProperties().getProperty("jspwiki.applicationName").trim();
7271

@@ -156,7 +155,7 @@ private void unregisterAdminBean( final AdminBean ab ) {
156155
private ObjectName getObjectName( final AdminBean ab ) throws MalformedObjectNameException {
157156
final String component = getJMXTitleString( ab.getType() );
158157
final String title = ab.getTitle();
159-
return new ObjectName(String.format("%s:component=%s,name=%s (%s)", Release.APPNAME, component, title, applicationName));
158+
return new ObjectName( String.format( "%s:component=%s,name=%s (%s)", Release.APPNAME, component, title, applicationName ) );
160159
}
161160

162161
/**
@@ -234,7 +233,12 @@ private MBeanServerFactory15()
234233
{}
235234

236235
public static MBeanServer getServer() {
237-
return ManagementFactory.getPlatformMBeanServer();
236+
try {
237+
return ManagementFactory.getPlatformMBeanServer();
238+
} catch( final Exception e ) {
239+
LOG.error( "Unable to obtain platform MBeanServer, JMX admin beans will not be available", e );
240+
return null;
241+
}
238242
}
239243
}
240244

@@ -260,21 +264,23 @@ public int getTypeFromString( final String type ) {
260264
*/
261265
@Override
262266
public void actionPerformed( final WikiEvent event ) {
263-
if( event instanceof WikiEngineEvent ) {
264-
if( event.getType() == WikiEngineEvent.SHUTDOWN ) {
265-
for( final AdminBean m_allBean : m_allBeans ) {
266-
try {
267-
final ObjectName on = getObjectName( m_allBean );
268-
if( m_mbeanServer.isRegistered( on ) ) {
269-
m_mbeanServer.unregisterMBean( on );
270-
LOG.info( "Unregistered AdminBean " + m_allBean.getTitle() );
267+
if( m_mbeanServer != null ) {
268+
if( event instanceof WikiEngineEvent ) {
269+
if( event.getType() == WikiEngineEvent.SHUTDOWN ) {
270+
for( final AdminBean m_allBean : m_allBeans ) {
271+
try {
272+
final ObjectName on = getObjectName( m_allBean );
273+
if( m_mbeanServer.isRegistered( on ) ) {
274+
m_mbeanServer.unregisterMBean( on );
275+
LOG.info( "Unregistered AdminBean " + m_allBean.getTitle() );
276+
}
277+
} catch( final MalformedObjectNameException e ) {
278+
LOG.error( "Malformed object name when unregistering", e );
279+
} catch( final InstanceNotFoundException e ) {
280+
LOG.error( "Object was registered; yet claims that it's not there", e );
281+
} catch( final MBeanRegistrationException e ) {
282+
LOG.error( "Registration exception while unregistering", e );
271283
}
272-
} catch( final MalformedObjectNameException e ) {
273-
LOG.error( "Malformed object name when unregistering", e );
274-
} catch( final InstanceNotFoundException e ) {
275-
LOG.error( "Object was registered; yet claims that it's not there", e );
276-
} catch( final MBeanRegistrationException e ) {
277-
LOG.error( "Registration exception while unregistering", e );
278284
}
279285
}
280286
}

0 commit comments

Comments
 (0)