Skip to content

Commit

Permalink
8274835: Remove unnecessary castings in java.base
Browse files Browse the repository at this point in the history
Reviewed-by: mullan, naoto, lancea, bpb
  • Loading branch information
turbanoff authored and dfuch committed Nov 12, 2021
1 parent 3b2585c commit 5a2452c
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/io/SequenceInputStream.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, 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 @@ -98,7 +98,7 @@ final void nextStream() throws IOException {

private void peekNextStream() {
if (e.hasMoreElements()) {
in = (InputStream) e.nextElement();
in = e.nextElement();
if (in == null)
throw new NullPointerException();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/ClassValue.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, 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 @@ -685,7 +685,7 @@ private Entry<?> findReplacement(Entry<?>[] cache, int home1) {
if (haveReplacement >= 0) {
if (cache[(replacementPos+1) & mask] != null) {
// Be conservative, to avoid breaking up a non-null run.
cache[replacementPos & mask] = (Entry<?>) Entry.DEAD_ENTRY;
cache[replacementPos & mask] = Entry.DEAD_ENTRY;
} else {
cache[replacementPos & mask] = null;
cacheLoad -= 1;
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Enum.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, 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 @@ -193,7 +193,7 @@ protected final Object clone() throws CloneNotSupportedException {
* method is the order in which the constants are declared.
*/
public final int compareTo(E o) {
Enum<?> other = (Enum<?>)o;
Enum<?> other = o;
Enum<E> self = this;
if (self.getClass() != other.getClass() && // optimization
self.getDeclaringClass() != other.getDeclaringClass())
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/StackTraceElement.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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 @@ -443,7 +443,7 @@ public int hashCode() {
*/
private synchronized void computeFormat() {
try {
Class<?> cls = (Class<?>) declaringClassObject;
Class<?> cls = declaringClassObject;
ClassLoader loader = cls.getClassLoader0();
Module m = cls.getModule();
byte bits = 0;
Expand Down
9 changes: 4 additions & 5 deletions src/java.base/share/classes/java/security/Signature.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, 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 @@ -1146,13 +1146,12 @@ private Delegate(Service service,
public Object clone() throws CloneNotSupportedException {
chooseFirstProvider();
if (sigSpi instanceof Cloneable) {
// Because 'algorithm' and 'provider' are private
// members of our supertype, we must perform a cast to
// access them.
// Because 'algorithm' is private member of our supertype,
// we must perform a cast to access it.
Signature that = new CloneableDelegate(
(SignatureSpi)sigSpi.clone(),
((Signature)this).algorithm);
that.provider = ((Signature)this).provider;
that.provider = this.provider;
return that;
} else {
throw new CloneNotSupportedException();
Expand Down
14 changes: 7 additions & 7 deletions src/java.base/share/classes/java/util/GregorianCalendar.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, 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 @@ -624,7 +624,7 @@ public GregorianCalendar(Locale aLocale) {
*/
public GregorianCalendar(TimeZone zone, Locale aLocale) {
super(zone, aLocale);
gdate = (BaseCalendar.Date) gcal.newCalendarDate(zone);
gdate = gcal.newCalendarDate(zone);
setTimeInMillis(System.currentTimeMillis());
}

Expand Down Expand Up @@ -698,7 +698,7 @@ public GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay,
GregorianCalendar(int year, int month, int dayOfMonth,
int hourOfDay, int minute, int second, int millis) {
super();
gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
gdate = gcal.newCalendarDate(getZone());
this.set(YEAR, year);
this.set(MONTH, month);
this.set(DAY_OF_MONTH, dayOfMonth);
Expand Down Expand Up @@ -736,7 +736,7 @@ public GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay,
*/
GregorianCalendar(TimeZone zone, Locale locale, boolean flag) {
super(zone, locale);
gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
gdate = gcal.newCalendarDate(getZone());
}

/////////////////
Expand Down Expand Up @@ -2370,7 +2370,7 @@ private int computeFields(int fieldMask, int tzMask) {
} else {
// Handle Julian calendar dates.
calsys = getJulianCalendarSystem();
cdate = (BaseCalendar.Date) jcal.newCalendarDate(getZone());
cdate = jcal.newCalendarDate(getZone());
jcal.getCalendarDateFromFixedDate(cdate, fixedDate);
Era e = cdate.getEra();
if (e == jeras[0]) {
Expand Down Expand Up @@ -3109,7 +3109,7 @@ private int actualMonthLength() {
return (int)(next1 - month1);
}
if (cdate != gdate) {
date = (BaseCalendar.Date) gcal.newCalendarDate(TimeZone.NO_TIMEZONE);
date = gcal.newCalendarDate(TimeZone.NO_TIMEZONE);
}
gcal.getCalendarDateFromFixedDate(date, next1);
next1 = getFixedDateMonth1(date, next1);
Expand Down Expand Up @@ -3198,7 +3198,7 @@ private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
if (gdate == null) {
gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
gdate = gcal.newCalendarDate(getZone());
cachedFixedDate = Long.MIN_VALUE;
}
setGregorianChange(gregorianCutover);
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/HashSet.java
Expand Up @@ -335,7 +335,7 @@ private void readObject(java.io.ObjectInputStream s)
.checkArray(s, Map.Entry[].class, HashMap.tableSizeFor(capacity));

// Create backing HashMap
map = (((HashSet<?>)this) instanceof LinkedHashSet ?
map = (this instanceof LinkedHashSet ?
new LinkedHashMap<>(capacity, loadFactor) :
new HashMap<>(capacity, loadFactor));

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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 @@ -612,7 +612,7 @@ public final <A> A[] toArray(IntFunction<A[]> generator) {
// Runtime checking will be performed when an element is stored in A[], thus if A is not a
// super type of U an ArrayStoreException will be thrown.
@SuppressWarnings("rawtypes")
IntFunction rawGenerator = (IntFunction) generator;
IntFunction rawGenerator = generator;
return (A[]) Nodes.flatten(evaluateToArrayNode(rawGenerator), rawGenerator)
.asArray(rawGenerator);
}
Expand Down
3 changes: 2 additions & 1 deletion src/java.base/share/classes/sun/net/www/MimeTable.java
Expand Up @@ -24,6 +24,7 @@
*/

package sun.net.www;

import jdk.internal.util.StaticProperty;

import java.io.*;
Expand Down Expand Up @@ -89,7 +90,7 @@ public static MimeTable getDefaultTable() {
*/
public static FileNameMap loadTable() {
MimeTable mt = getDefaultTable();
return (FileNameMap)mt;
return mt;
}

public synchronized int getSize() {
Expand Down
Expand Up @@ -77,7 +77,7 @@ public synchronized AuthCacheValue get (String pkey, String skey) {
}
if (skey == null) {
// list should contain only one element
return (AuthenticationInfo)list.get (0);
return list.get(0);
}
for (AuthCacheValue authCacheValue : list) {
AuthenticationInfo inf = (AuthenticationInfo) authCacheValue;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, 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 @@ -122,7 +122,7 @@ public DSAParams getParams() {
return null;
}
paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
return (DSAParams)paramSpec;
return paramSpec;
}
} catch (InvalidParameterSpecException e) {
return null;
Expand Down
Expand Up @@ -291,7 +291,6 @@ private static X500Principal getTargetSubject(List<CertStore> stores,
for (CertStore store : stores) {
try {
Collection<? extends Certificate> certs =
(Collection<? extends Certificate>)
store.getCertificates(sel);
if (!certs.isEmpty()) {
X509Certificate xc =
Expand Down
Expand Up @@ -792,8 +792,7 @@ private void checkOCSP(X509Certificate cert,
e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
}

RevocationStatus rs =
(RevocationStatus)response.getSingleResponse(certId);
RevocationStatus rs = response.getSingleResponse(certId);
RevocationStatus.CertStatus certStatus = rs.getCertStatus();
if (certStatus == RevocationStatus.CertStatus.REVOKED) {
Date revocationTime = rs.getRevocationTime();
Expand Down
Expand Up @@ -1036,7 +1036,7 @@ public java.security.cert.Certificate[] getPeerCertificates()
// Certs are immutable objects, therefore we don't clone them.
// But do need to clone the array, so that nothing is inserted
// into peerCerts.
return (java.security.cert.Certificate[])peerCerts.clone();
return peerCerts.clone();
}

/**
Expand All @@ -1054,8 +1054,7 @@ public java.security.cert.Certificate[] getLocalCertificates() {
// clone to preserve integrity of session ... caller can't
// change record of peer identity even by accident, much
// less do it intentionally.
return (localCerts == null ? null :
(java.security.cert.Certificate[])localCerts.clone());
return (localCerts == null ? null : localCerts.clone());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/sun/util/calendar/Era.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, 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 @@ -80,7 +80,7 @@ public Era(String name, String abbr, long since, boolean localTime) {
this.since = since;
this.localTime = localTime;
Gregorian gcal = CalendarSystem.getGregorianCalendar();
BaseCalendar.Date d = (BaseCalendar.Date) gcal.newCalendarDate(null);
BaseCalendar.Date d = gcal.newCalendarDate(null);
gcal.getCalendarDate(since, d);
sinceDate = new ImmutableGregorianDate(d);
}
Expand Down

1 comment on commit 5a2452c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.