Skip to content

[Bug]: Schema.types lazy initialization is not thread-safe #119

@Splatcrafter

Description

@Splatcrafter

AI REVIEWED

Module: api
File: api/schema/Schema.java (~line 164-167)
Severity: High

Summary

The lazy initialization of Schema.types uses a bare null-check without synchronization:

if (this.types == null) {
    this.types = this.buildTypes();
}

Multiple threads calling types() concurrently could both pass the null-check and invoke buildTypes() simultaneously, leading to race conditions or duplicate initialization.

Expected Behavior

Thread-safe lazy initialization — buildTypes() should execute at most once regardless of concurrent access.

Actual Behavior

Data race: multiple threads can trigger buildTypes() concurrently.

Suggested Fix

Use one of:

  • synchronized block on the method or a private lock object
  • Double-checked locking with a volatile field
  • Lazy holder idiom (static inner class)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions