From f042f8b553b5a08cfb98e349f6dd7c0fc1987816 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 8 Jul 2019 21:02:40 +0100 Subject: [PATCH] HHH-13496 Formula using unsafe concurrent initialization of its unique identifier --- .../src/main/java/org/hibernate/mapping/Formula.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java b/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java index f044ea54f9..31955fa886 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java @@ -7,6 +7,7 @@ package org.hibernate.mapping; import java.io.Serializable; +import java.util.concurrent.atomic.AtomicInteger; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.SQLFunctionRegistry; @@ -20,13 +21,14 @@ import static org.hibernate.internal.util.StringHelper.safeInterning; * @author Gavin King */ public class Formula implements Selectable, Serializable { - private static int formulaUniqueInteger; + + private static final AtomicInteger formulaUniqueInteger = new AtomicInteger(); private String formula; - private int uniqueInteger; + private final int uniqueInteger; public Formula() { - uniqueInteger = formulaUniqueInteger++; + uniqueInteger = formulaUniqueInteger.incrementAndGet(); } public Formula(String formula) {