diff --git a/src/java.base/share/classes/java/util/ResourceBundle.java b/src/java.base/share/classes/java/util/ResourceBundle.java index b9a2dca88d5..147f098aac9 100644 --- a/src/java.base/share/classes/java/util/ResourceBundle.java +++ b/src/java.base/share/classes/java/util/ResourceBundle.java @@ -719,8 +719,7 @@ public abstract class ResourceBundle { if (this == other) { return true; } - try { - final CacheKey otherEntry = (CacheKey)other; + if (other instanceof CacheKey otherEntry) { //quick check to see if they are not equal if (modulesHash != otherEntry.modulesHash) { return false; @@ -738,7 +737,6 @@ public abstract class ResourceBundle { Module caller = getCallerModule(); return ((module != null) && (module.equals(otherEntry.getModule())) && (caller != null) && (caller.equals(otherEntry.getCallerModule()))); - } catch (NullPointerException | ClassCastException e) { } return false; } diff --git a/src/java.base/share/classes/sun/util/resources/Bundles.java b/src/java.base/share/classes/sun/util/resources/Bundles.java index f54892d9af7..14247f0d347 100644 --- a/src/java.base/share/classes/sun/util/resources/Bundles.java +++ b/src/java.base/share/classes/sun/util/resources/Bundles.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -502,15 +502,13 @@ public abstract class Bundles { if (this == other) { return true; } - try { - final CacheKey otherEntry = (CacheKey)other; + if (other instanceof CacheKey otherEntry) { //quick check to see if they are not equal if (hashCodeCache != otherEntry.hashCodeCache) { return false; } return locale.equals(otherEntry.locale) && name.equals(otherEntry.name); - } catch (NullPointerException | ClassCastException e) { } return false; }