Skip to content

Commit

Permalink
Prevent reloading of default message instance when an error is encoun…
Browse files Browse the repository at this point in the history
…tered

This fixes #119

PiperOrigin-RevId: 554536199
  • Loading branch information
l46kok authored and copybara-github committed Aug 7, 2023
1 parent eb75304 commit 86114e0
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 86114e0

Please sign in to comment.