Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6D04D200B56 for ; Sat, 30 Jul 2016 18:41:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6B5FB160A8A; Sat, 30 Jul 2016 16:41:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8BAA0160A63 for ; Sat, 30 Jul 2016 18:41:07 +0200 (CEST) Received: (qmail 29934 invoked by uid 500); 30 Jul 2016 16:41:06 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 29916 invoked by uid 99); 30 Jul 2016 16:41:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 Jul 2016 16:41:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id D8AF01A0597 for ; Sat, 30 Jul 2016 16:41:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.179 X-Spam-Level: ** X-Spam-Status: No, score=2.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id le7PK5Q0Mk9t for ; Sat, 30 Jul 2016 16:41:04 +0000 (UTC) Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 429125F24E for ; Sat, 30 Jul 2016 16:41:03 +0000 (UTC) Received: by mail-oi0-f42.google.com with SMTP id j185so143925465oih.0 for ; Sat, 30 Jul 2016 09:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=6fZfN+pIKWheX3wNES2h4PSLI1aG4PIFDz/Yy6IDA8w=; b=z4H/GrGN6Xs679RxYi5kkZL1kBkI7Bxu6JfdvXOVk/Jxdix83LyMEbt+Qc/F4scrBS djtgSPlMRz1FR5QstN32CEXZcmfLWWZwAyVuza54FHvXBFN5GwNJjvDG8IiBXMp3Hz6E 0doRn9ppY2n7yKiCS3j4EpNyVGrmp9dsbZgCt+fBHBkD/utzTu89h4xEQtQmZRLU2OM1 XHHYSQucsviNyrsC4XrPCwbgx6p0vzMNwBxjS+bpJ/eCUJQAvgxDrTku9O6X82C5a2TB 7RGKX5WYBREroTdcQKRsyDwwGns1sjm6P/y72CSPDlD3YeGZ9iGPk8mV8h8XUA4Izu/M e2ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=6fZfN+pIKWheX3wNES2h4PSLI1aG4PIFDz/Yy6IDA8w=; b=hrgQoNPMG7eWhQj6giUibzoFx8VGQL/qLIpwm6/+ESwL/lKagt6lOhQfLKac/iNYIs coNnoqWAwXjOSZGNabT55d+j3ZEswTytPj3nBpfSWXSKJ8S24XAjzio2VN4+mbKwqti1 PnF8zXTFEVtZggO8pHIj1vfm/MUekn5wVyPZ5QhuB8RA+hx5W4PjYBn1+GFCHdcQx8wc zxFPDYAoUqwaPDfMFOX3GBTLr1K2Wrn+DZWRy4mqFNCdrno9wM3mi6l3GpqBUm2dg7us V1X4U6H9wLmZ1d1f6/S6RGgcOzNDYOcESgrA9rz/GKIU2/Beyx4MVDienL3XOhilgZZa k1dg== X-Gm-Message-State: AEkoouuT35Ty3WHZzA4TO+KqE+a2LTGesk3m9mo534uwd+qoGp9jyrwqULe+zHBXsC7BP3GdCr3hTwx/Txb2+w== X-Received: by 10.202.114.209 with SMTP id p200mr29333210oic.183.1469896862083; Sat, 30 Jul 2016 09:41:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.20.2 with HTTP; Sat, 30 Jul 2016 09:41:01 -0700 (PDT) Received: by 10.157.20.2 with HTTP; Sat, 30 Jul 2016 09:41:01 -0700 (PDT) In-Reply-To: References: <0b4c82e96fcb4a49830913fadbd8c3ae@git.apache.org> <4BE74B73-95CD-42F5-AE5A-8E7C6BC15624@gmail.com> From: Gary Gregory Date: Sat, 30 Jul 2016 09:41:01 -0700 Message-ID: Subject: Re: [LANG] LANG-1252 - NumberUtils.isNumber and NumberUtils.createNumber resolve inconsistently To: Commons Developers List Content-Type: multipart/alternative; boundary=001a11c1770a5230ea0538dd087b archived-at: Sat, 30 Jul 2016 16:41:08 -0000 --001a11c1770a5230ea0538dd087b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Can this all be solved with better Javadocs? Gary On Jul 29, 2016 7:59 AM, "Rob Tompkins" wrote: > Hi Benedikt, > > Thanks for the insights here. > > > On Jul 29, 2016, at 3:53 AM, Benedikt Ritter wrote= : > > > > Hello Rob, > > > > Rob Tompkins > schrieb > am Do., 28. Juli 2016 um > > 14:23 Uhr: > > > >> In short, I=E2=80=99m trying to generalize LANG-1060, LANG-1040, LANG-= 1038, and > >> LANG-992 with a single issue that actually hits all the bases here wit= h > >> NumberUtils.isNumber. > >> > >> Bug (1): > >> > >> System.out.println(lang.math.NumberUtils.isNumber(=E2=80=9C+2= =E2=80=9D)); ----> > >> false > >> > >> while > >> > >> System.out.println(lang.math.NumberUtils.createNumber(=E2=80=9C= +2)); > ----> > >> 2 > >> > >> Bug (2): > >> > >> > >> System.out.println(lang.math.NumberUtils.isNumber(=E2=80=9C01.5= =E2=80=9D)); ----> > >> false > >> > >> while > >> > >> System.out.println(lang.math.NumberUtils.createNumber(=E2=80=9C= 01.5)); > >> ----> 1.5. > >> > >> > >> > >> It seems to me that we could externalize a considerable amount of the > code > >> underlying the two methods into shared methods, as it seems like all t= he > >> validations in createNumber that predicate object creation should be > >> directly used in isNumber. I would love to hear folks=E2=80=99 thought= s. > >> > > > > I think it is important to pay close attention to the JavaDocs in this > case. > > > > NumberUtils.isNumber : > > Checks whether the String a valid Java number. > > > > This has nothing to do with createNumber: > > NumberUtils.createNumber: Turns a string value into a java.lang.Number > > > > What you're probably looking for is: > > > > NumberUtils.isParsebale: Checks whether the given String is a parsable > > number. > > > > The difference is, that isNumber tells you, whether putting the given > > String into Java code woul compile, while isParseble stells you whether= a > > call to createNumber will be successful. > > This feels confusing to me (mainly because I=E2=80=99m not clear of the c= ontext of > the word =E2=80=9Ccompile=E2=80=9D here). But, I=E2=80=99m mostly agnosti= c regarding intent here. > So let=E2=80=99s not concern ourselves with that. > > Maybe the Jira issue that I created, LANG-1252, should just make the > javadoc clearer in this case. > > Along the same line of thought, in NumberUtilsTest > testIsNumber() > calls the function > private void compareIsNumberWithCreateNumber(final String val, final > boolean expected) { > final boolean isValid =3D NumberUtils.isNumber(val); > final boolean canCreate =3D checkCreateNumber(val); > if (isValid =3D=3D expected && canCreate =3D=3D expected) { > return; > } > fail("Expecting "+ expected + " for isNumber/createNumber using \"" + > val + "\" but got " + isValid + " and " + canCreate); > } > where =E2=80=9CcheckCreateNumber=E2=80=9D is declared as: > private boolean checkCreateNumber(final String val) { > try { > final Object obj =3D NumberUtils.createNumber(val); > if (obj =3D=3D null) { > return false; > } > return true; > } catch (final NumberFormatException e) { > return false; > } > } > which continues to puzzle me. If, indeed, it is the case that isNumber an= d > createNumber necessarily differ, might we also refactor the unit tests as > part of LANG-1252 such that they aren=E2=80=99t directly correlated for t= he sake of > validation? > > Again, many thanks for the response here. > > Cheers, > -Rob > > > > > Regards, > > Benedikt > > > > > >> Cheers, > >> -Rob > > --001a11c1770a5230ea0538dd087b--