Skip to content

refactor: make Terminal.SCROLL_BACK_COUNT static final - #34

Merged
loki5512344 merged 1 commit into
DivByDiamond:workfrom
pocketprobe:refactor/work/scrollback-count-static-final-rebase
Sep 1, 2026
Merged

refactor: make Terminal.SCROLL_BACK_COUNT static final#34
loki5512344 merged 1 commit into
DivByDiamond:workfrom
pocketprobe:refactor/work/scrollback-count-static-final-rebase

Conversation

@pocketprobe

Copy link
Copy Markdown
Contributor

Summary

SCROLL_BACK_COUNT was a public int instance field on Terminal, but it is never
assigned after declaration — it is a constant that controls scrollback buffer sizing
(buffer allocation, scrollback cap logic, diff row sizing). This makes it
public static final int, matching the existing HEIGHT convention, and updates the
instance-qualified reads (terminal.SCROLL_BACK_COUNT) to class-qualified reads.

No behavior change. No new tests — the existing buffer-sizing tests already assert
against SCROLL_BACK_COUNT.

Why

A public mutable field participating in index arithmetic can be desynchronized from
buffers already allocated with the old value (external mutation after construction →
ArrayIndexOutOfBoundsException). static final closes that at compile time.

This does not change the SpotBugs baseline: the MS_SHOULD_BE_FINAL entries in
config/spotbugs/baseline.xml belong to Config and ImplementedPrivateModes, and
that rule targets static fields, which this never was.

Verification

Cherry-picked onto upstream/work @ 3e48b183 (original branch was five merges back;
applied clean, no conflicts). Clean build in a fresh worktree (no prior build directory):

  • ./gradlew clean build — BUILD SUCCESSFUL
  • :test: 284 tests, 0 failures, 0 skipped
  • PMD main: 0 violations; Checkstyle main: 0 errors; SpotBugs: green

5 files, +12/−12.

Assisted by: GLM (syn:large:text on synthetic.new) — code generation and review.

SCROLL_BACK_COUNT was a public mutable int field, read in index arithmetic
buffer allocation, scrollback cap logic, and diff sizing. It was never
assigned after declaration—verified via grep showing ONLY the public field
declaration (line 48).

Making it static final matches HEIGHT convention and prevents external
mutation from desynchronizing the field from already-allocated buffers,
which would cause ArrayIndexOutOfBoundsException. This is a no-behavior-
change hardening change.

Instance-qualified reads (terminal.SCROLL_BACK_COUNT) updated to class-
qualified static access (Terminal.SCROLL_BACK_COUNT) in:
- src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java (~2 reads)
- src/main/java/li/cil/oc2/common/vm/terminal/buffer/TerminalBufferScrolling.java (~3 reads)
- src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH8.java (1 read)
- src/test/java/li/cil/oc2/common/vm/terminal/TerminalBufferTest.java (~5 reads)

Internal unqualified reads in Terminal.java left as-is (conventional).

§36 M6: class-qualified access for static fields preferred globally.

No new tests needed—all existing buffer-sizing tests use SCROLL_BACK_COUNT
for assertions and will adapt to the static qualifier automatically.

Assisted by: GLM (syn:large:text on synthetic.new) — code generation and review.
@pocketprobe
pocketprobe marked this pull request as ready for review September 1, 2026 20:07
@loki5512344
loki5512344 merged commit 2038b41 into DivByDiamond:work Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants