Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/java.base/share/classes/java/net/URLConnection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -611,10 +611,12 @@ public Map<String,List<String>> getHeaderFields() {
* missing or malformed.
*/
public int getHeaderFieldInt(String name, int Default) {
String value = getHeaderField(name);
try {
return Integer.parseInt(value);
} catch (Exception e) { }
final String value = getHeaderField(name);
if (value != null) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) { }
}
return Default;
}

Expand All @@ -634,10 +636,12 @@ public int getHeaderFieldInt(String name, int Default) {
* @since 1.7
*/
public long getHeaderFieldLong(String name, long Default) {
String value = getHeaderField(name);
try {
return Long.parseLong(value);
} catch (Exception e) { }
final String value = getHeaderField(name);
if (value != null) {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) { }
}
return Default;
}

Expand All @@ -659,10 +663,12 @@ public long getHeaderFieldLong(String name, long Default) {
*/
@SuppressWarnings("deprecation")
public long getHeaderFieldDate(String name, long Default) {
String value = getHeaderField(name);
try {
return Date.parse(value);
} catch (Exception e) { }
final String value = getHeaderField(name);
if (value != null) {
try {
return Date.parse(value);
} catch (Exception e) { }
}
return Default;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1938,9 +1938,12 @@ private InputStream getInputStream0() throws IOException {
continue;
}

try {
cl = Long.parseLong(responses.findValue("content-length"));
} catch (Exception exc) { };
final String contentLengthVal = responses.findValue("content-length");
if (contentLengthVal != null) {
try {
cl = Long.parseLong(contentLengthVal);
} catch (NumberFormatException nfe) { }
}

if (method.equals("HEAD") || cl == 0 ||
respCode == HTTP_NOT_MODIFIED ||
Expand Down