You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/03/29 12:59:14 UTC

[camel] branch master updated: Fix potential race condition in double-checked locking object initialization (as reported by lgtm.com) by making the assignment to the shared variable the last statement of the synchronized block. (#3688)

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ed0fc2  Fix potential race condition in double-checked locking object initialization (as reported by lgtm.com) by making the assignment to the shared variable the last statement of the synchronized block. (#3688)
3ed0fc2 is described below

commit 3ed0fc2d5daa53f221c58164ed4a9f6cc26f31c6
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Sun Mar 29 14:58:59 2020 +0200

    Fix potential race condition in double-checked locking object initialization (as reported by lgtm.com) by making the assignment to the shared variable the last statement of the synchronized block. (#3688)
---
 .../org/apache/camel/component/mock/MockExpressionClause.java    | 9 +++++----
 .../src/main/java/org/apache/camel/builder/ExpressionClause.java | 9 +++++----
 .../java/org/apache/camel/support/builder/ExpressionBuilder.java | 5 +++--
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
index e3d1397..7f6d3ea 100644
--- a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
+++ b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
@@ -433,11 +433,12 @@ public class MockExpressionClause<T> implements Expression, Predicate {
         if (expr == null) {
             synchronized (this) {
                 if (expr == null) {
-                    expr = getExpressionValue();
-                    if (expr == null) {
-                        expr = getExpressionType().createExpression(context);
+                    Expression newExpression = getExpressionValue();
+                    if (newExpression == null) {
+                        newExpression = getExpressionType().createExpression(context);
                     }
-                    expr.init(context);
+                    newExpression.init(context);
+                    expr = newExpression;
                 }
             }
         }
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java b/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java
index caeb6f9..8bb2327 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java
@@ -946,11 +946,12 @@ public class ExpressionClause<T> implements Expression, Predicate {
         if (expr == null) {
             synchronized (this) {
                 if (expr == null) {
-                    expr = getExpressionValue();
-                    if (expr == null) {
-                        expr = delegate.getExpressionType().createExpression(context);
+                    Expression newExpression = getExpressionValue();
+                    if (newExpression == null) {
+                        newExpression = delegate.getExpressionType().createExpression(context);
                     }
-                    expr.init(context);
+                    newExpression.init(context);
+                    expr = newExpression;
                 }
             }
         }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
index d9c0a3a..4b41702 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
@@ -695,8 +695,9 @@ public class ExpressionBuilder {
                             if (lan != null) {
                                 pred = lan.createPredicate(expression);
                                 pred.init(context);
-                                expr = lan.createExpression(expression);
-                                expr.init(context);
+                                Expression newExpression = lan.createExpression(expression);
+                                newExpression.init(context);
+                                expr = newExpression;
                             } else {
                                 throw new NoSuchLanguageException(language);
                             }