From 9794f1727bf7b1f96d1504a326672f05d68b8a6b Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Mon, 24 Oct 2011 19:13:57 +0000 Subject: [PATCH] ICU-8854 unchecked/unconfirmed cast. X-SVN-Rev: 30853 --- .../com/ibm/icu/impl/ICULocaleService.java | 19 ++++++++++------ .../ibm/icu/text/NumberFormatServiceShim.java | 22 +++++++++---------- .../com/ibm/icu/util/CalendarServiceShim.java | 20 ++++++++--------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULocaleService.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULocaleService.java index 22bbbdbb641..4ce1dbdac0e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULocaleService.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICULocaleService.java @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2010, International Business Machines Corporation and * + * Copyright (C) 2001-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -486,14 +486,19 @@ public class ICULocaleService extends ICUService { * Returns the service object if kind/locale match. Service is not used. */ public Object create(Key key, ICUService service) { + if (!(key instanceof LocaleKey)) { + return null; + } + LocaleKey lkey = (LocaleKey)key; - if (kind == LocaleKey.KIND_ANY || kind == lkey.kind()) { - String keyID = lkey.currentID(); - if (id.equals(keyID)) { - return obj; - } + if (kind != LocaleKey.KIND_ANY && kind != lkey.kind()) { + return null; } - return null; + if (!id.equals(lkey.currentID())) { + return null; + } + + return obj; } protected boolean isSupportedID(String idToCheck) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormatServiceShim.java b/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormatServiceShim.java index 7318dc0e943..c3a6185e3bc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormatServiceShim.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormatServiceShim.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2003-2010, International Business Machines Corporation and * + * Copyright (C) 2003-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -48,18 +48,16 @@ class NumberFormatServiceShim extends NumberFormat.NumberFormatShim { } public Object create(Key key, ICUService srvc) { - if (handlesKey(key)) { - LocaleKey lkey = (LocaleKey)key; - ULocale loc = lkey.canonicalLocale(); - int kind = lkey.kind(); - - Object result = delegate.createFormat(loc, kind); - if (result == null) { - result = srvc.getKey(key, null, this); - } - return result; + if (!handlesKey(key) || !(key instanceof LocaleKey)) { + return null; + } + + LocaleKey lkey = (LocaleKey)key; + Object result = delegate.createFormat(lkey.canonicalLocale(), lkey.kind()); + if (result == null) { + result = srvc.getKey(key, null, this); } - return null; + return result; } protected Set getSupportedIDs() { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/CalendarServiceShim.java b/icu4j/main/classes/core/src/com/ibm/icu/util/CalendarServiceShim.java index c249626fcdb..6c572e40fa7 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/CalendarServiceShim.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/CalendarServiceShim.java @@ -1,5 +1,5 @@ /* -* Copyright (C) 2007-2010, International Business Machines +* Copyright (C) 2007-2011, International Business Machines * Corporation and others. All Rights Reserved. */ @@ -43,16 +43,16 @@ class CalendarServiceShim extends Calendar.CalendarShim { } public Object create(Key key, ICUService srvc) { - if (handlesKey(key)) { - LocaleKey lkey = (LocaleKey)key; - ULocale loc = lkey.canonicalLocale(); - Object result = delegate.createCalendar(loc); - if (result == null) { - result = srvc.getKey(key, null, this); - } - return result; + if (!handlesKey(key) || !(key instanceof LocaleKey)) { + return null; + } + + LocaleKey lkey = (LocaleKey)key; + Object result = delegate.createCalendar(lkey.canonicalLocale()); + if (result == null) { + result = srvc.getKey(key, null, this); } - return null; + return result; } protected Set getSupportedIDs() { -- 2.40.0