8301964: Expensive fillInStackTrace operation in HttpURLConnection.getLastModified when no last-modified in response

Reviewed-by: dfuchs, jpai, alanb
This commit is contained in:
Andrey Turbanov 2023-02-25 13:39:36 +00:00
parent 1dbd18ac63
commit 3a9f491caa
3 changed files with 32 additions and 32 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -599,16 +599,18 @@ public abstract class HttpURLConnection extends URLConnection {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public long getHeaderFieldDate(String name, long Default) { public long getHeaderFieldDate(String name, long defaultValue) {
String dateString = getHeaderField(name); String dateString = getHeaderField(name);
try { if (dateString != null) {
if (!dateString.contains("GMT")) { if (!dateString.contains("GMT")) {
dateString = dateString+" GMT"; dateString = dateString + " GMT";
}
try {
return Date.parse(dateString);
} catch (Exception e) {
} }
return Date.parse(dateString);
} catch (Exception e) {
} }
return Default; return defaultValue;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,6 @@ import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.ServiceConfigurationError; import java.util.ServiceConfigurationError;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -612,20 +611,20 @@ public abstract class URLConnection {
* headers. Classes for that connection type can override this method * headers. Classes for that connection type can override this method
* and short-circuit the parsing. * and short-circuit the parsing.
* *
* @param name the name of the header field. * @param name the name of the header field.
* @param Default the default value. * @param defaultValue the default value.
* @return the value of the named field, parsed as an integer. The * @return the value of the named field, parsed as an integer. The
* {@code Default} value is returned if the field is * {@code defaultValue} value is returned if the field is
* missing or malformed. * missing or malformed.
*/ */
public int getHeaderFieldInt(String name, int Default) { public int getHeaderFieldInt(String name, int defaultValue) {
final String value = getHeaderField(name); final String value = getHeaderField(name);
if (value != null) { if (value != null) {
try { try {
return Integer.parseInt(value); return Integer.parseInt(value);
} catch (NumberFormatException e) { } } catch (NumberFormatException e) { }
} }
return Default; return defaultValue;
} }
/** /**
@ -636,21 +635,21 @@ public abstract class URLConnection {
* headers. Classes for that connection type can override this method * headers. Classes for that connection type can override this method
* and short-circuit the parsing. * and short-circuit the parsing.
* *
* @param name the name of the header field. * @param name the name of the header field.
* @param Default the default value. * @param defaultValue the default value.
* @return the value of the named field, parsed as a long. The * @return the value of the named field, parsed as a long. The
* {@code Default} value is returned if the field is * {@code defaultValue} value is returned if the field is
* missing or malformed. * missing or malformed.
* @since 1.7 * @since 1.7
*/ */
public long getHeaderFieldLong(String name, long Default) { public long getHeaderFieldLong(String name, long defaultValue) {
final String value = getHeaderField(name); final String value = getHeaderField(name);
if (value != null) { if (value != null) {
try { try {
return Long.parseLong(value); return Long.parseLong(value);
} catch (NumberFormatException e) { } } catch (NumberFormatException e) { }
} }
return Default; return defaultValue;
} }
/** /**
@ -663,21 +662,21 @@ public abstract class URLConnection {
* headers. Classes for that connection type can override this method * headers. Classes for that connection type can override this method
* and short-circuit the parsing. * and short-circuit the parsing.
* *
* @param name the name of the header field. * @param name the name of the header field.
* @param Default a default value. * @param defaultValue a default value.
* @return the value of the field, parsed as a date. The value of the * @return the value of the field, parsed as a date. The value of the
* {@code Default} argument is returned if the field is * {@code defaultValue} argument is returned if the field is
* missing or malformed. * missing or malformed.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public long getHeaderFieldDate(String name, long Default) { public long getHeaderFieldDate(String name, long defaultValue) {
final String value = getHeaderField(name); final String value = getHeaderField(name);
if (value != null) { if (value != null) {
try { try {
return Date.parse(value); return Date.parse(value);
} catch (Exception e) { } } catch (Exception e) { }
} }
return Default; return defaultValue;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -38,7 +38,6 @@ import java.util.Map;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import sun.net.util.IPAddressUtil; import sun.net.util.IPAddressUtil;
import sun.net.www.http.HttpClient;
/** /**
* A class to represent an HTTP connection to a remote object. * A class to represent an HTTP connection to a remote object.
@ -352,8 +351,8 @@ public class HttpsURLConnectionImpl
return delegate.getResponseMessage(); return delegate.getResponseMessage();
} }
public long getHeaderFieldDate(String name, long Default) { public long getHeaderFieldDate(String name, long defaultValue) {
return delegate.getHeaderFieldDate(name, Default); return delegate.getHeaderFieldDate(name, defaultValue);
} }
public Permission getPermission() throws IOException { public Permission getPermission() throws IOException {
@ -392,12 +391,12 @@ public class HttpsURLConnectionImpl
return delegate.getLastModified(); return delegate.getLastModified();
} }
public int getHeaderFieldInt(String name, int Default) { public int getHeaderFieldInt(String name, int defaultValue) {
return delegate.getHeaderFieldInt(name, Default); return delegate.getHeaderFieldInt(name, defaultValue);
} }
public long getHeaderFieldLong(String name, long Default) { public long getHeaderFieldLong(String name, long defaultValue) {
return delegate.getHeaderFieldLong(name, Default); return delegate.getHeaderFieldLong(name, defaultValue);
} }
public Object getContent() throws IOException { public Object getContent() throws IOException {