From 3a9f491caa04db8b367129c50892bc669e5765bd Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Sat, 25 Feb 2023 13:39:36 +0000 Subject: [PATCH] 8301964: Expensive fillInStackTrace operation in HttpURLConnection.getLastModified when no last-modified in response Reviewed-by: dfuchs, jpai, alanb --- .../classes/java/net/HttpURLConnection.java | 16 +++++---- .../share/classes/java/net/URLConnection.java | 33 +++++++++---------- .../https/HttpsURLConnectionImpl.java | 15 ++++----- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/java.base/share/classes/java/net/HttpURLConnection.java b/src/java.base/share/classes/java/net/HttpURLConnection.java index 7ac41329d6b..b501fa25e45 100644 --- a/src/java.base/share/classes/java/net/HttpURLConnection.java +++ b/src/java.base/share/classes/java/net/HttpURLConnection.java @@ -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. * * 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") - public long getHeaderFieldDate(String name, long Default) { + public long getHeaderFieldDate(String name, long defaultValue) { String dateString = getHeaderField(name); - try { + if (dateString != null) { 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; } diff --git a/src/java.base/share/classes/java/net/URLConnection.java b/src/java.base/share/classes/java/net/URLConnection.java index ea283ae48d0..e3b451ae898 100644 --- a/src/java.base/share/classes/java/net/URLConnection.java +++ b/src/java.base/share/classes/java/net/URLConnection.java @@ -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. * * 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.Date; import java.util.Iterator; -import java.util.Locale; import java.util.Objects; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; @@ -612,20 +611,20 @@ public abstract class URLConnection { * headers. Classes for that connection type can override this method * and short-circuit the parsing. * - * @param name the name of the header field. - * @param Default the default value. + * @param name the name of the header field. + * @param defaultValue the default value. * @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. */ - public int getHeaderFieldInt(String name, int Default) { + public int getHeaderFieldInt(String name, int defaultValue) { final String value = getHeaderField(name); if (value != null) { try { return Integer.parseInt(value); } 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 * and short-circuit the parsing. * - * @param name the name of the header field. - * @param Default the default value. + * @param name the name of the header field. + * @param defaultValue the default value. * @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. * @since 1.7 */ - public long getHeaderFieldLong(String name, long Default) { + public long getHeaderFieldLong(String name, long defaultValue) { final String value = getHeaderField(name); if (value != null) { try { return Long.parseLong(value); } 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 * and short-circuit the parsing. * - * @param name the name of the header field. - * @param Default a default value. + * @param name the name of the header field. + * @param defaultValue a default value. * @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. */ @SuppressWarnings("deprecation") - public long getHeaderFieldDate(String name, long Default) { + public long getHeaderFieldDate(String name, long defaultValue) { final String value = getHeaderField(name); if (value != null) { try { return Date.parse(value); } catch (Exception e) { } } - return Default; + return defaultValue; } /** diff --git a/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java b/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java index b3a42cc9137..2096957d289 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java +++ b/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java @@ -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. * * 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.Optional; import sun.net.util.IPAddressUtil; -import sun.net.www.http.HttpClient; /** * A class to represent an HTTP connection to a remote object. @@ -352,8 +351,8 @@ public class HttpsURLConnectionImpl return delegate.getResponseMessage(); } - public long getHeaderFieldDate(String name, long Default) { - return delegate.getHeaderFieldDate(name, Default); + public long getHeaderFieldDate(String name, long defaultValue) { + return delegate.getHeaderFieldDate(name, defaultValue); } public Permission getPermission() throws IOException { @@ -392,12 +391,12 @@ public class HttpsURLConnectionImpl return delegate.getLastModified(); } - public int getHeaderFieldInt(String name, int Default) { - return delegate.getHeaderFieldInt(name, Default); + public int getHeaderFieldInt(String name, int defaultValue) { + return delegate.getHeaderFieldInt(name, defaultValue); } - public long getHeaderFieldLong(String name, long Default) { - return delegate.getHeaderFieldLong(name, Default); + public long getHeaderFieldLong(String name, long defaultValue) { + return delegate.getHeaderFieldLong(name, defaultValue); } public Object getContent() throws IOException {