Skip to content

Fix bugs found in a code review - #177

Merged
tastybento merged 5 commits into
developfrom
fix/audit-bugs
Nov 17, 2026
Merged

tastybento merged 5 commits into
developfrom
fix/audit-bugs

Conversation

@tastybento

@tastybento tastybento commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Results of a review of the whole addon. Every fix below was checked against the code, and the behavioural ones have tests that fail on develop and pass here.

Data loss

  • database import wiped all generators before loading the file. importDatabaseFile called wipeGameModeGenerators (which deletes the tiers from the database) and only then tried to load the file. A typo in the file name, or an empty or broken file, left the game mode with no generators. The admin wasn't told in chat either, because the error only went to the console. The file is now loaded first, the wipe only happens once it loaded, and the admin gets the no-file message.

Crashes

  • activateGenerator NPE: with overwrite-on-active, if the island was at its limit and the active generator had since been deleted, getGeneratorByID returned null and deactivateGenerator threw. The stale id is now removed to free the slot, matching autoActivateGenerator.
  • database tab completion: listFiles() can return null.

Security (admin-only)

  • Path traversal: database import/export <file> and template import <file> accepted ../, so they could read or write files outside the addon folder. A new resolveDataFile helper rejects any name that doesn't land directly inside the data folder.

GUI

  • Height-range errors never shown: the panel used admin.errors.* instead of stone-generator.errors.*, min-height-greater-than-max didn't exist in any locale, and every locale used [MIN]/[MAX] while Constants.MIN/MAX are [min]/[max]. Fixed the key path, added the en-US key, lower-cased the placeholders in all locales, and the panel now reopens after the error instead of staying closed.
  • Empty extra page: CommonPagedPanel, PagedSelector and the block/treasure pages of GeneratorEditPanel clamped to size / 21, which is one past the last page when size is a multiple of 21. In GeneratorEditPanel the wrap-around arrows reach it directly (Previous on page 1, or Next on the last page). In the others it shows up after deleting items while on the last page.

Threading

  • GitHub library download: the import ran on the async download thread, which touches the generator cache, database and players. It's now handed to the main thread.

Checked and not changed

  • Weighted random ceilingEntry: correct for cumulative upper-bound keys, and it can't return null.
  • Bank withdrawal race: with the current Bank addon every failure completes synchronously, so the activation/purchase can't succeed before a failure is seen.
  • GeneratorTierObject.clone() skipping blockHeightRanges: clone() is used by database export, but blockHeightRanges isn't read anywhere (per-block heights use materialHeightMap, which is cloned), so nothing is lost.

Test plan

  • New tests: missing and empty import files don't wipe generators; ../ is rejected for template import and by resolveDataFile; activating over a deleted active generator doesn't throw and frees the slot
  • The new tests fail against develop
  • mvn test: 171 passed, 0 failures
  • Manual: set a block height range with min > max in the edit panel and check the error message shows the numbers

Note: min-height-greater-than-max is only in en-US; other locales fall back to English until synced.

🤖 Generated with Claude Code

tastybento and others added 2 commits November 16, 2026 20:55
- Database import wiped all of a game mode's generator tiers before
  loading the file, so a typo in the file name (or an empty/broken file)
  deleted every generator. Now the file is loaded first and the old
  generators are only removed once it loaded; the admin is told in chat
  when the file is not found.
- activateGenerator threw a NullPointerException when overwrite-on-active
  needed to free a slot held by a generator that has since been deleted.
  The stale id is now dropped instead.
- Database import/export and template import accepted file names like
  "../x", reaching files outside the addon folder. They are now refused.
- Height-range error messages in the generator edit panel never showed:
  wrong key path, a missing min-height key, and [MIN]/[MAX] placeholders
  that did not match the [min]/[max] constants. The panel now also
  reopens after the error.
- Paged panels showed an empty extra page when the item count was an
  exact multiple of 21 (reachable through the wrap-around arrows in the
  generator edit panel, or by deleting items on the last page).
- GitHub library downloads ran the import on an async thread; it now
  runs on the main thread.
- Database command tab completion no longer throws if the addon folder
  cannot be listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Minimum/Maximum Height buttons on the main generator edit panel
accepted any value, so min could be set above max (e.g. min 150, max
100), which stops the generator working at every height. Reject such
values with the same error messages as the per-block height panel.

Also fix the en-US tooltip for these buttons: they set the range for the
whole generator, not "this material".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tastybento

Copy link
Copy Markdown
Member Author

Found in manual testing: the generator-wide Minimum/Maximum Height buttons on the main edit panel had no min/max check either, so min 150 / max 100 could be saved, and the generator then works at no height. They now reject such values with the same error messages as the per-block panel. Also fixed their en-US tooltip, which said "for this material" instead of "for this generator".

Titles built from a name ("Generator: Starting Nether Generator") ran past
the edge of the window, because the client does not cut long titles.

- Generator, bundle and island panels now show just the name as the
  title, giving it the full width.
- Names are shortened with an ellipsis when they still do not fit,
  measured with the default Minecraft font widths (bold). The Height
  Range panel keeps its label and shortens the block name the same way.
- The Spanish and Vietnamese titles used translated placeholders
  ([generador], [paquete], [isla], [gói]), so the name never appeared.
  Rewriting the title values fixes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tastybento

Copy link
Copy Markdown
Member Author

Added: admin panel titles no longer run past the edge of the inventory window. Generator/bundle/island panels show just the name, shortened with "…" if it still doesn't fit (measured with the default Minecraft font widths). The Height Range panel keeps its label. This also fixes the Spanish and Vietnamese titles, which used translated placeholders and never showed the name.

tastybento and others added 2 commits November 16, 2026 21:24
The number formatter used owner.getLocale(), but owner is null on spawn
islands and islands without an owner. Format with the purchasing user's
locale instead: they are the one who receives the messages.

Fixes Sonar java:S2259.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reliability (quality gate):
- IslandEditPanel: read the island name before getGeneratorData, whose
  null check made Sonar treat the island as nullable.
- IslandEditPanel: null-safe game mode name in three button descriptions.
- canPurchaseGenerator NPE: cherry-picked from #176.

Code smells in StoneGeneratorImportManager: constants for repeated
literals, rename a local that hid a field, extract export error
reporting to cut complexity, make DefaultJSONHandler fields final.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@tastybento
tastybento merged commit b5f536c into develop Nov 17, 2026
4 checks passed
@tastybento tastybento mentioned this pull request Nov 17, 2026
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.

1 participant