我正在使用Jackrabbit 2.13.1。

为什么AccessDeniedException导致会话泄漏?

        try {
            session = repository.login(creds); //here are creds for user without permissions, just for testing
        } catch (Throwable t) {
            if (session != null) {
                session.logout();
            }
            Throwables.propagateIfInstanceOf(t, javax.jcr.RepositoryException.class);
            throw Throwables.propagate(t);
        }

如预期的那样,这将引发AccessDeniedException:
Caused by: javax.jcr.LoginException: Workspace access denied
    at org.apache.jackrabbit.core.RepositoryImpl.login(RepositoryImpl.java:1529)
    at org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:144)
    at ttt.createSession(RepositoryManager.java:132)
    ... 51 common frames omitted

Caused by: javax.jcr.AccessDeniedException: Not allowed to access Workspace default
    at org.apache.jackrabbit.core.security.DefaultAccessManager.init(DefaultAccessManager.java:159)
    at org.apache.jackrabbit.core.DefaultSecurityManager.getAccessManager(DefaultSecurityManager.java:280)
    at org.apache.jackrabbit.core.SessionImpl.createAccessManager(SessionImpl.java:356)
    at org.apache.jackrabbit.core.SessionImpl.<init>(SessionImpl.java:273)
    at org.apache.jackrabbit.core.SessionImpl.<init>(SessionImpl.java:239)
    at org.apache.jackrabbit.core.XASessionImpl.<init>(XASessionImpl.java:101)
    at org.apache.jackrabbit.core.RepositoryImpl.createSessionInstance(RepositoryImpl.java:1613)
    at org.apache.jackrabbit.core.RepositoryImpl.createSession(RepositoryImpl.java:956)
    at org.apache.jackrabbit.core.RepositoryImpl.login(RepositoryImpl.java:1501)

session为null,因此无法调用注销。但是会抛出未关闭的会话检测到的异常:
WARN  o.a.jackrabbit.core.SessionImpl - Unclosed session detected. The session was opened here:
java.lang.Exception: Stack Trace
    at org.apache.jackrabbit.core.SessionImpl.<init>(SessionImpl.java:222)
    at org.apache.jackrabbit.core.SessionImpl.<init>(SessionImpl.java:239)
    at org.apache.jackrabbit.core.XASessionImpl.<init>(XASessionImpl.java:101)
    at org.apache.jackrabbit.core.RepositoryImpl.createSessionInstance(RepositoryImpl.java:1613)
    at org.apache.jackrabbit.core.RepositoryImpl.createSession(RepositoryImpl.java:956)
    at org.apache.jackrabbit.core.RepositoryImpl.login(RepositoryImpl.java:1501)
    at org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:144)
    at ttt.createSession(RepositoryManager.java:132)

最佳答案

很好,这听起来很像,它仍然存在于2.13.3中,并且在SessionImpl的构造函数中抛出异常的情况下会发生,因此将听起来很清晰,然后部分地创建了会话,但仍将其视为 Activity 会话当前代码会将即将被GC视为会话泄漏,这就是为什么您收到此警告。

我刚刚为此https://issues.apache.org/jira/browse/JCR-4033创建了票证

09-07 20:13