Skip to content

Commit f248c71

Browse files
committed
fix: Adjust timeout and exception handling for URLDownload compatibility
- Import java.time.Duration for timeout settings - Use Duration.ofMillis() for setConnectTimeout (URLDownload only supports connect timeout) - Remove setReadTimeout (not supported by URLDownload class) - Change catch block to ParseException | FetcherException (IOException not thrown) - Code now compiles successfully
1 parent 64b8d07 commit f248c71

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

jablib/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.net.URI;
66
import java.net.URISyntaxException;
77
import java.net.URL;
8+
import java.time.Duration;
89
import java.util.List;
910
import java.util.Optional;
1011

@@ -58,7 +59,6 @@ public class INSPIREFetcher implements SearchBasedParserFetcher, EntryBasedFetch
5859

5960
// Timeout configuration (in milliseconds)
6061
private static final int CONNECT_TIMEOUT_MS = 10000; // 10 seconds
61-
private static final int READ_TIMEOUT_MS = 30000; // 30 seconds
6262

6363
private static final String ERROR_MESSAGE_TEMPLATE =
6464
"Failed to fetch from INSPIRE using %s after %d attempts.\n" +
@@ -99,9 +99,8 @@ public URLDownload getUrlDownload(URL url) {
9999
download.addHeader("Accept", MediaTypes.APPLICATION_BIBTEX);
100100
download.addHeader("User-Agent", "JabRef/" + getClass().getPackage().getImplementationVersion());
101101

102-
// Set timeouts to prevent hanging
103-
download.setConnectTimeout(CONNECT_TIMEOUT_MS);
104-
download.setReadTimeout(READ_TIMEOUT_MS);
102+
// Set connection timeout to prevent hanging
103+
download.setConnectTimeout(Duration.ofMillis(CONNECT_TIMEOUT_MS));
105104

106105
return download;
107106
}
@@ -288,7 +287,7 @@ private List<BibEntry> performSearchWithRetry(URL url, String identifier) throws
288287
results.forEach(this::doPostCleanup);
289288
return results;
290289

291-
} catch (ParseException | IOException e) {
290+
} catch (ParseException | FetcherException e) {
292291
lastException = new FetcherException(url,
293292
"Failed to fetch from INSPIRE (attempt " + (attempt + 1) + "): " + e.getMessage(), e);
294293

0 commit comments

Comments
 (0)