From 86114e04d0099c88480b37452ad9af895dc5dea6 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Mon, 7 Aug 2023 11:20:00 -0700 Subject: [PATCH] Prevent reloading of default message instance when an error is encountered This fixes https://github.com/google/cel-java/issues/119 PiperOrigin-RevId: 554536199 --- .../cel/common/internal/DefaultInstanceMessageFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/dev/cel/common/internal/DefaultInstanceMessageFactory.java b/common/src/main/java/dev/cel/common/internal/DefaultInstanceMessageFactory.java index 75aa7a21e..131b1cf10 100644 --- a/common/src/main/java/dev/cel/common/internal/DefaultInstanceMessageFactory.java +++ b/common/src/main/java/dev/cel/common/internal/DefaultInstanceMessageFactory.java @@ -196,16 +196,18 @@ private boolean hasConflictingClassName(FileDescriptor file, String name) { private static final class LazyGeneratedMessageDefaultInstance { private final String fullClassName; private volatile Message defaultInstance = null; + private volatile boolean loaded = false; public LazyGeneratedMessageDefaultInstance(String fullClassName) { this.fullClassName = fullClassName; } public Message getDefaultInstance() { - if (defaultInstance == null) { + if (!loaded) { synchronized (this) { - if (defaultInstance == null) { + if (!loaded) { loadDefaultInstance(); + loaded = true; } } }