Skip to content

Conversation

@usc
Copy link
Contributor

@usc usc commented Jul 30, 2025

问题:打开大部分节点时候空白,出现 Unknown Error(-1)

主题总数使用千分位,直接转换int会报错,
e.g.
主题总数 137,647

Caused by: java.lang.NumberFormatException: For input string: "137,647"
at java.lang.Integer.parseInt(Integer.java:781)
at java.lang.Integer.valueOf(Integer.java:1108)
at me.ghui.fruit.bind.PickAdapters.parseElement(PickAdapters.java:103)
at me.ghui.fruit.bind.PickAdapters.access$000(PickAdapters.java:17)
at me.ghui.fruit.bind.PickAdapters$2.read(PickAdapters.java:33)
at me.ghui.fruit.bind.PickAdapters$2.read(PickAdapters.java:30)
at me.ghui.fruit.bind.ReflectivePickAdapterFactory$1.read(ReflectivePickAdapterFactory.java:111)
at me.ghui.fruit.bind.ReflectivePickAdapterFactory$Adapter.read(ReflectivePickAdapterFactory.java:64)
at me.ghui.fruit.Fruit.fromHtml(Fruit.java:61)
at me.ghui.fruit.Fruit.fromHtml(Fruit.java:49)
at me.ghui.fruit.converter.retrofit.FruitResponseBodyConverter.convert(FruitResponseBodyConverter.java:28)
at me.ghui.fruit.converter.retrofit.FruitResponseBodyConverter.convert(FruitResponseBodyConverter.java:15)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:246)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:207)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:46)
at io.reactivex.Observable.subscribe(Observable.java:12284)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
at io.reactivex.Observable.subscribe(Observable.java:12284)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:608)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at java.lang.Thread.run(Thread.java:1119)

@graycreate graycreate requested a review from Copilot September 13, 2025 13:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a NumberFormatException that occurs when parsing topic counts containing thousand separators (commas) from HTML content. The fix addresses the issue where topic counts like "137,647" would fail to parse as integers.

  • Changed data type from int to String for the raw extracted value
  • Implemented proper parsing logic to handle comma-separated numbers
  • Added exception handling to gracefully handle parsing errors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

this.items = items;
}

public int getTotal() {
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

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

This method could throw a NullPointerException if totalStr is null. Add a null check before processing the string.

Suggested change
public int getTotal() {
public int getTotal() {
if (totalStr == null || totalStr.isEmpty()) {
return 0;
}

Copilot uses AI. Check for mistakes.
return total;
try {
return Integer.parseInt(totalStr.replaceAll("[^0-9]", ""));
} catch (Exception e) {
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

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

Catching generic Exception is too broad. Catch specific exceptions like NumberFormatException or NullPointerException for better error handling and debugging.

Suggested change
} catch (Exception e) {
} catch (NumberFormatException | NullPointerException e) {

Copilot uses AI. Check for mistakes.
@graycreate graycreate merged commit 39f9b59 into v2er-app:main Sep 18, 2025
@graycreate
Copy link
Member

Thank you for your contribution.

graycreate added a commit that referenced this pull request Sep 18, 2025
- Rename totalStr to totalCountRaw for better clarity
- Add null/empty check before parsing
- Use specific NumberFormatException instead of generic Exception
- Add error logging for failed parsing attempts
- Add descriptive comment explaining the field purpose

This is a follow-up to PR #82, implementing improvements suggested by GitHub Copilot review.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
graycreate added a commit that referenced this pull request Sep 18, 2025
…#115)

- Rename totalStr to totalCountRaw for better clarity
- Add null/empty check before parsing
- Use specific NumberFormatException instead of generic Exception
- Add error logging for failed parsing attempts
- Add descriptive comment explaining the field purpose

This is a follow-up to PR #82, implementing improvements suggested by GitHub Copilot review.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <[email protected]>
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