使用 HttpURLConnection 替换 HttpClient 实现#6219
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces the usage of Java's HttpClient and HttpResponse with HttpURLConnection across various download and fetch tasks, updating UrlResponseInfo to wrap HttpURLConnection metadata. Additionally, it increases the default retry count to 5, increases the default buffer size to 32KB, and reduces the network timeout to 10 seconds. The review feedback highlights a potential NullPointerException in UrlResponseInfo when copying header values if they contain null elements, suggesting a safe filtering approach.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| LinkedHashMap<String, List<String>> headers = new LinkedHashMap<>(); | ||
| for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) { | ||
| String name = entry.getKey(); | ||
| List<String> values = entry.getValue(); | ||
| if (name != null && values != null) { | ||
| headers.put(name, List.copyOf(values)); | ||
| } | ||
| } | ||
| return HttpHeaders.of(headers, (name, value) -> true); |
There was a problem hiding this comment.
Using List.copyOf(values) can throw a NullPointerException if the values list contains any null elements. While standard HTTP headers typically do not have null values, some custom or mock URLConnection implementations (e.g., in tests or plugins) might return lists containing null elements.
To prevent potential NullPointerExceptions, we can filter out any null elements using Java Streams before collecting them into an unmodifiable list.
| LinkedHashMap<String, List<String>> headers = new LinkedHashMap<>(); | |
| for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) { | |
| String name = entry.getKey(); | |
| List<String> values = entry.getValue(); | |
| if (name != null && values != null) { | |
| headers.put(name, List.copyOf(values)); | |
| } | |
| } | |
| return HttpHeaders.of(headers, (name, value) -> true); | |
| LinkedHashMap<String, List<String>> headers = new LinkedHashMap<>(); | |
| for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) { | |
| String name = entry.getKey(); | |
| List<String> values = entry.getValue(); | |
| if (name != null && values != null) { | |
| headers.put(name, values.stream().filter(v -> v != null).toList()); | |
| } | |
| } | |
| return HttpHeaders.of(headers, (name, value) -> true); |
#6215