commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Cordova (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DBCP-476) AbandonedTrace.getTrace() contains race condition
Date Wed, 26 Apr 2017 05:54:04 GMT

    [ https://issues.apache.org/jira/browse/DBCP-476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15984216#comment-15984216
] 

Richard Cordova commented on DBCP-476:
--------------------------------------

Suggested (untested) fix:
{code}
            while (iter.hasNext()) {
                AbandonedTrace trace = iter.next().get();
                if (trace == null) {
                    // Clean-up since we are here anyway
                    iter.remove();
                } else {
                    result.add(trace);
                }
            }
{code}

> AbandonedTrace.getTrace() contains race condition
> -------------------------------------------------
>
>                 Key: DBCP-476
>                 URL: https://issues.apache.org/jira/browse/DBCP-476
>             Project: Commons Dbcp
>          Issue Type: Bug
>            Reporter: Richard Cordova
>            Priority: Minor
>
> The clean up code in AbandonedTrace is subject to the reference being cleared in between
the condition being checked and the referent being added to the result.
> {code}
>             while (iter.hasNext()) {
>                 WeakReference<AbandonedTrace> ref = iter.next();
>                 if (ref.get() == null) {
>                     // Clean-up since we are here anyway
>                     iter.remove();
>                 } else {
>                     result.add(ref.get());
>                 }
>             }
> {code}
> This can surface as a NullPointerException, e.g.
> {noformat}
> Caused by: java.lang.NullPointerException
> 	at org.apache.tomcat.dbcp.dbcp2.DelegatingStatement.close(DelegatingStatement.java:149)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message