Skip to content

Fix listener leak: eliminate transient MarketPrices instantiation and remove BUListener inheritance#88

Closed
Copilot wants to merge 3 commits intorefactor/bazaar-structsfrom
copilot/sub-pr-83
Closed

Fix listener leak: eliminate transient MarketPrices instantiation and remove BUListener inheritance#88
Copilot wants to merge 3 commits intorefactor/bazaar-structsfrom
copilot/sub-pr-83

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

Every call to resolveInput in TransactionAmount and TransactionCost created a new MarketPrices(productId) just to read a price once. Since MarketPrices extends BUListener, each instance permanently self-registers in ListenerManager.listeners and subscribes to the event bus — with no unsubscribe path — leaking on every sign interaction.

Changes

  • MarketPrices: Added static getPriceForPosition(String productId, PricingPosition, OrderType) that queries BazaarDataManager directly and applies the same ±0.1 offset. The instance overload now delegates to this static method instead of duplicating the switch logic. With no event handling remaining, the class no longer extends BUListener — removing the cache fields (buyPriceInfo, sellPriceInfo), the @EventHandler, the private updateMarketPrices(String) helper, and the subscribe() call. MarketPrices is now a plain value class with no listener registration:
// Before — leaks a BUListener on every resolveInput call
MarketPrices marketPrices = new MarketPrices(state.productId);
return new ResolvedInput.Value(marketPrices.getPriceForPosition(getPricingPosition(), getOrderType()));

// After — no instance needed; static call reads fresh from BazaarDataManager
return new ResolvedInput.Value(MarketPrices.getPriceForPosition(state.productId(), getPricingPosition(), getOrderType()));
  • SignInputHelper: Removed transient new MarketPrices(...) from both TransactionAmount.resolveInput and TransactionCost.resolveInput; dropped the now-dead MarketPrices parameter from computeFixedValue and computeMaxValue.
  • InstantBuyAmountHelper, BuyOrderAmountHelper, SellOfferAmountHelper: Updated computeFixedValue signatures to match; removed unused MarketPrices import.

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…ce lookup

Co-authored-by: mkram17 <53064237+mkram17@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 15, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • piston-meta.mojang.com
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xmx4G -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [WIP] Fix MarketPrices implementation in SignInputHelper Fix listener leak: replace transient MarketPrices instantiation with static price lookup Mar 15, 2026
Copilot AI requested a review from mkram17 March 15, 2026 17:33
sellPriceOpt.ifPresent(price -> sellPriceInfo.setPricePerItem(Util.truncateNum(price)));
}

public Double getPriceForPosition(PricingPosition pricingPosition, OrderType orderType) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot make this method use the static one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit df5bc60. The instance method now delegates to the static overload. With no event handler remaining, I also removed the dead buyPriceInfo/sellPriceInfo fields, the updateMarketPrices(String) private helper, the @EventHandler, extends BUListener, and the subscribe() call — so MarketPrices is now a plain value class with no listener registration at all.

… BUListener inheritance

Co-authored-by: mkram17 <53064237+mkram17@users.noreply.github.com>
Copilot AI changed the title Fix listener leak: replace transient MarketPrices instantiation with static price lookup Fix listener leak: eliminate transient MarketPrices instantiation and remove BUListener inheritance Mar 16, 2026
Copilot AI requested a review from mkram17 March 16, 2026 19:31
@mkram17 mkram17 closed this Mar 16, 2026
@mkram17 mkram17 deleted the copilot/sub-pr-83 branch March 16, 2026 21:23
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