You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2021/06/04 08:56:35 UTC

[commons-jexl] branch master updated: Call Lock.lock before the try

This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git


The following commit(s) were added to refs/heads/master by this push:
     new c45b357  Call Lock.lock before the try
     new b54b3c9  Merge pull request #56 from csamak/obtain-lock
c45b357 is described below

commit c45b35726534513d131069e00b07aa7e734629c3
Author: Cameron Samak <cs...@apache.org>
AuthorDate: Fri Jun 4 03:05:32 2021 +0000

    Call Lock.lock before the try
    
    Probably not an issue with the ReentrantReadWriteLock implementation of
    Lock.
    Other lock usage in Introspector already calls lock before the try.
    
    See:
    https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html
    https://errorprone.info/bugpattern/LockNotBeforeTry
---
 .../apache/commons/jexl3/internal/introspection/Introspector.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java
index b2d384c..3c13839 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java
@@ -300,15 +300,15 @@ public final class Introspector {
      */
     private ClassMap getMap(final Class<?> c) {
         ClassMap classMap;
+        lock.readLock().lock();
         try {
-            lock.readLock().lock();
             classMap = classMethodMaps.get(c);
         } finally {
             lock.readLock().unlock();
         }
         if (classMap == null) {
+            lock.writeLock().lock();
             try {
-                lock.writeLock().lock();
                 // try again
                 classMap = classMethodMaps.get(c);
                 if (classMap == null) {
@@ -334,8 +334,8 @@ public final class Introspector {
             cloader = getClass().getClassLoader();
         }
         if (!cloader.equals(loader)) {
+            lock.writeLock().lock();
             try {
-                lock.writeLock().lock();
                 // clean up constructor and class maps
                 final Iterator<Map.Entry<MethodKey, Constructor<?>>> mentries = constructorsMap.entrySet().iterator();
                 while (mentries.hasNext()) {