Bug 41682

Summary: ClassCastException with BackupManager + debug logging
Product: Tomcat 6 Reporter: Graham Johnson <gjohnson>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 6.0.7   
Target Milestone: default   
Hardware: Other   
OS: other   

Description Graham Johnson 2007-02-22 13:05:50 UTC
(Still happening in 6.0.9, though that isn't an option in Bugzilla)

If I use the BackupManager for session replication AND turn on debug logging, I
get this exception when I try to invalidate the session:

java.lang.ClassCastException: org.apache.catalina.ha.session.BackupManager
cannot be cast to org.apache.catalina.ha.session.DeltaManager
	at org.apache.catalina.ha.session.DeltaSession.expire(DeltaSession.java:361)
	at org.apache.catalina.ha.session.DeltaSession.expire(DeltaSession.java:352)
	at org.apache.catalina.session.StandardSession.expire(StandardSession.java:660)
	at
org.apache.catalina.session.StandardSession.invalidate(StandardSession.java:1112)
	at
org.apache.catalina.session.StandardSessionFacade.invalidate(StandardSessionFacade.java:150)

The bug is easy to find in the source.  If debug logging is enabled, it tries to
cast manager to DeltaManager without an instanceof, even though it is doing an
instanceof immediately after:

    public void expire(boolean notify, boolean notifyCluster) {
        String expiredId = getIdInternal();
        super.expire(notify);

        if (notifyCluster) {
            if (log.isDebugEnabled())
                log.debug(sm.getString("deltaSession.notifying",
                                       ((DeltaManager)manager).getName(),
                                       new Boolean(isPrimarySession()),
                                       expiredId));
            if ( manager instanceof DeltaManager ) {
                ( (DeltaManager) manager).sessionExpired(expiredId);
            }
        }
    }
Comment 1 Filip Hanik 2007-03-26 23:52:24 UTC
Thanks for the report