Skip to content

fix(keys): build PublicKey.ZERO without reading Key32.zero - #1666

Merged
bmc08gt merged 1 commit into
code/cashfrom
fix/key32-init-order
Oct 2, 2026
Merged

bmc08gt merged 1 commit into
code/cashfrom
fix/key32-init-order

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

A test that touched Key32.mock before anything had loaded PublicKey failed with ExceptionInInitializerError at Key.kt:51. Every later test in the same JVM that used a key then failed with NoClassDefFoundError. While working on #1664, one new test in :services:opencode took 17 of 20 tests down with it.

Key32's companion builds PublicKeys, which initializes PublicKey's companion, and PublicKey.ZERO was built from Key32.zero. zero is the last field in Key32's companion, so it was still null when ZERO read it:

NullPointerException: ... because the return value of "Key32$Companion.getZero()" is null
    at com.getcode.solana.keys.PublicKey.<clinit>(PublicKey.kt:31)

ZERO now builds its bytes from LENGTH_32 directly. The app was not exposed: no production code constructs a Key32 or reads its companion, and initializing PublicKey, Mint or Vault initializes Key32 first as their superclass, an order that already worked.

KeyInitOrderTest loads Key32 first in a fresh class loader, so it checks this order no matter what earlier tests in the JVM have loaded. It fails without the change.

Key32's companion constructs PublicKeys. When Key32 initialized first,
PublicKey's companion ran while Key32.zero was still null, and
PublicKey.ZERO threw. Both classes then failed to initialize for the rest
of the JVM, which broke every later test that used a key.
@bmc08gt bmc08gt self-assigned this Oct 2, 2026
@github-actions github-actions Bot added area: crypto Solana, keys, encryption, signing type: fix Bug fix labels Oct 2, 2026
@bmc08gt
bmc08gt merged commit e81304e into code/cash Oct 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: crypto Solana, keys, encryption, signing type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant