8297211: Expensive fillInStackTrace operation in HttpURLConnection.getOutputStream0 when no content-length in response
Reviewed-by: simonis, dfuchs
This commit is contained in:
parent
5a45c25151
commit
392ac7055d
@ -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
|
||||
@ -619,10 +619,12 @@ public abstract class URLConnection {
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -642,10 +644,12 @@ public abstract class URLConnection {
|
||||
* @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;
|
||||
}
|
||||
|
||||
@ -667,10 +671,12 @@ public abstract class URLConnection {
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
|
@ -1932,9 +1932,12 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
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 ||
|
||||
|
Loading…
Reference in New Issue
Block a user