-
Notifications
You must be signed in to change notification settings - Fork 47
fix the total topic count with thousand separators #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
inttoStringfor 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() { |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
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.
| public int getTotal() { | |
| public int getTotal() { | |
| if (totalStr == null || totalStr.isEmpty()) { | |
| return 0; | |
| } |
| return total; | ||
| try { | ||
| return Integer.parseInt(totalStr.replaceAll("[^0-9]", "")); | ||
| } catch (Exception e) { |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
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.
| } catch (Exception e) { | |
| } catch (NumberFormatException | NullPointerException e) { |
|
Thank you for your contribution. |
- 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]>
…#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]>
问题:打开大部分节点时候空白,出现 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)