You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2011/01/06 20:38:29 UTC

DO NOT REPLY [Bug 50554] New: Bad use of getClass() could potentially lead to concurrency bugs in future

https://issues.apache.org/bugzilla/show_bug.cgi?id=50554

           Summary: Bad use of getClass() could potentially lead to
                    concurrency bugs in future
           Product: Tomcat 7
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: reprogrammer@gmail.com


The method
org.apache.naming.java.javaURLContextFactory.getInitialContext(Hashtable<?,?>)
has a synchronized block on getClass(). Using getClass() as lock is a bug
pattern because if some class subclasses javaURLContextFactory and
getInitialContext gets called on an instance of such a subclass, getClass()
will return a different Class object for that instance. Locking different
objects for different classes is usually not the expected behavior. Therefore,
I suggest to remove this bug pattern by simply replacing getClass() by
javaURLContextFactory.class.

See
https://www.securecoding.cert.org/confluence/display/java/LCK02-J.+Do+not+synchronize+on+the+class+object+returned+by+getClass%28%29
for more information about this bug pattern.

Keshmesh (https://github.com/reprogrammer/keshmesh/) is an Eclipse plugin that
analyzes the source code of Java programs to detect concurrency bug patterns
such the one I reported.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 50554] Bad use of getClass() could potentially lead to concurrency bugs in future

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50554

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #1 from Mark Thomas <ma...@apache.org> 2011-01-07 05:32:45 EST ---
Fixed in 7.0.x and will be included in 7.0.6

The issue was already reported by FindBugs. I fixed this issue and the handful
of other FindBugs and Eclipse warnings in that class.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 50554] Bad use of getClass() could potentially lead to concurrency bugs in future

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50554

Mohsen Vakilian <re...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reprogrammer@gmail.com

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org