Re: RFR: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Roger Riggs
(had only run the java/lang/invoke tests >> locally). An alternative approach here is to verify all methods already >> implicitly check null and remove all these, but being explicit is nice and >> reduces possibility of surprise. > > I found few more similar places

Re: RFR: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Andrey Turbanov
ng explicit is nice and reduces > possibility of surprise. I found few more similar places in JFR code, where `Objects.nonNull` is used incorrectly. jdk.jfr.internal.consumer.AbstractEventStream#setStartTime jdk.jfr.consumer.EventStream#openRepository(java.nio.file.Path) jdk.jfr.Recording#setFlushInterval - PR: https://git.openjdk.java.net/jdk/pull/2914

Integrated: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Claes Redestad
14 mod 8263380: Unintended use of Objects.nonNull in VarHandles Reviewed-by: rriggs - PR: https://git.openjdk.java.net/jdk/pull/2914

Re: RFR: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Claes Redestad
On Wed, 10 Mar 2021 16:04:59 GMT, Jorn Vernee wrote: > Nice catch! > > We have a test that is supposed to test this: > https://github.com/openjdk/jdk/blob/master/test/jdk/java/foreign/TestNulls.java > But it is only checking if an NPE is thrown, and not checking for a message, > since

Re: RFR: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Jorn Vernee
On Wed, 10 Mar 2021 16:04:22 GMT, Roger Riggs wrote: >> Use requireNonNull instead. > > Well spotted. Nice catch! We have a test that is supposed to test this: https://github.com/openjdk/jdk/blob/master/test/jdk/java/foreign/TestNulls.java But it is only checking if an NPE is thrown, and not

Re: RFR: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Roger Riggs
On Wed, 10 Mar 2021 15:33:43 GMT, Claes Redestad wrote: > Use requireNonNull instead. Well spotted. - Marked as reviewed by rriggs (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/2914

RFR: 8263380: Unintended use of Objects.nonNull in VarHandles

2021-03-10 Thread Claes Redestad
Use requireNonNull instead. - Commit messages: - Unintended use of Objects.nonNull in VarHandles Changes: https://git.openjdk.java.net/jdk/pull/2914/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk=2914=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8263380 Stats

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-06-25 Thread Mike Duigou
I am sympathetic to this naming issue (actually indifferent is more accurate) but it will have to wait until I return from vacation. I have tagged this thread and will follow up when I am back in the office. Please be patient, it will be addressed. Mike On Jun 20 2013, at 07:10 , Remi Forax

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-06-24 Thread Jack Moxley
Really depends about whether you want the method to be bad English, or really bad English. :-). All this double negativity gets me down. What's wrong with exists() ? Sent from my iPhone On 20 Jun 2013, at 08:24, Howard Lovatt howard.lov...@gmail.com wrote: I would say not needed, !isNull()

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-06-24 Thread Howard Lovatt
I would say not needed, !isNull() is sufficient. If included isNotNull() is the better name. On 5 May 2013 01:09, Ulf Zibis ulf.zi...@cosoco.de wrote: Am 04.05.2013 04:28, schrieb Mike Duigou: I have updated the webrev to include incorporate the feedback I have received.

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-06-20 Thread Stephen Colebourne
Like others, I would prefer isNotNull() to notNull(). Mainly for consistency, but also for dicoverability is IDE autocomplete (as the methods would then be next to one another) Stephen On 30 April 2013 23:45, Mike Duigou mike.dui...@oracle.com wrote: Hello all; Another changeset coming from

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-06-20 Thread Remi Forax
Yes, a fine idea. Rémi On 06/20/2013 11:44 AM, Stephen Colebourne wrote: Like others, I would prefer isNotNull() to notNull(). Mainly for consistency, but also for dicoverability is IDE autocomplete (as the methods would then be next to one another) Stephen On 30 April 2013 23:45, Mike

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-05-04 Thread Ulf Zibis
Am 04.05.2013 04:28, schrieb Mike Duigou: I have updated the webrev to include incorporate the feedback I have received. http://cr.openjdk.java.net/~mduigou/JDK-8013712/1/webrev/ Regarding the naming of the nonNull method. I originally added this method in 2011 but I've forgotten since then

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-05-03 Thread Mike Duigou
I have updated the webrev to include incorporate the feedback I have received. http://cr.openjdk.java.net/~mduigou/JDK-8013712/1/webrev/ Regarding the naming of the nonNull method. I originally added this method in 2011 but I've forgotten since then why it has the name it does. As best as I

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-05-02 Thread Jeff Hain
Hello. nonNull could be renamed into isNonNull, else people might use it instead of requireNonNull, especially if they are already used to a pre-Java 7 requireNonNull that would be called nonNull. (example:

RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-04-30 Thread Mike Duigou
Hello all; Another changeset coming from the lambda libraries effort. This one is two small additions to the Objects class. The introduced methods are not really intended to be used directly, comparison operators work better in imperative logic, but the methods will be very useful as

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-04-30 Thread Mandy Chung
On 4/30/2013 3:45 PM, Mike Duigou wrote: Hello all; Another changeset coming from the lambda libraries effort. This one is two small additions to the Objects class. The introduced methods are not really intended to be used directly, comparison operators work better in imperative logic, but

Re: RFR : 8013712 : (XS) Add Objects.nonNull and Objects.isNull

2013-04-30 Thread Mike Duigou
I will make both suggested changes. Thank you. Mike On Apr 30 2013, at 20:34 , Mandy Chung wrote: On 4/30/2013 3:45 PM, Mike Duigou wrote: Hello all; Another changeset coming from the lambda libraries effort. This one is two small additions to the Objects class. The introduced methods

Re: Objects.nonNull()

2011-01-21 Thread Bruce Chapman
On 15/01/2011 12:30 a.m., Stephen Colebourne wrote: snip 5) Now *** If you are time-pressured, I'd recommend removing this method from v7. *** A defaultIfNull method would be much more useful in this class: public static Object defaultIfNull(Object object, Object defaultValue) {

Re: Objects.nonNull()

2011-01-17 Thread Stephen Colebourne
On 17 January 2011 05:26, Brian Goetz brian.go...@oracle.com wrote: My aversion to checkNonNull naming pattern comes from experience.  Long, long ago in a code base far, far away I wrote a big set of unit tests using this pattern.  Coming back to it months later I had to read the code very

Re: Objects.nonNull()

2011-01-16 Thread mark . reinhold
Date: Thu, 13 Jan 2011 19:52:27 -0500 From: brian.go...@oracle.com Mark Reinhold wrote: I'm still troubled by the check prefix, though. It implies that the named condition will be tested but it doesn't clearly relate the result of that test to the method's exception-throwing behavior.

Re: Objects.nonNull()

2011-01-16 Thread Brian Goetz
I still don't like checkNonNull. It checks whether its argument is non-null, but then what does it do? Throw an exception if it is non-null? Throw an exception if it isn't? Do something else? My aversion to checkNonNull naming pattern comes from experience. Long, long ago in a code base

Re: Objects.nonNull()

2011-01-16 Thread Ariel Weisberg
Hi all, As a user the first name that came to mind was expect. Expect doesn't imply a specific error signaling pattern, but it does imply that it is an error if the condition is not as expected. Expect is only one letter less than throwIf, but it doesn't include a capital letter. expectNonNull:

Re: Objects.nonNull()

2011-01-14 Thread Stephen Colebourne
There are a number of strands to this thread 1) Null useful or not. There are arguments on both sides here, and developers are divided. Personally, I use null every single day to use not known or not required, such as in a search request: /** * The set of exchange object identifiers, null

Re: Objects.nonNull()

2011-01-14 Thread Ulf Zibis
Am 14.01.2011 12:30, schrieb Stephen Colebourne: 2) Other utilities These are prior art that users are familiar with, just as much as the JDK. Google Guava - Objects: public staticT T firstNonNull(T first, T second) why not? : public static T T firstNonNull(T... values) Commons Lang -

Re: Objects.nonNull()

2011-01-14 Thread Tom Hawtin
On 14/01/2011 11:30, Stephen Colebourne wrote: These are prior art that users are familiar with, just as much as the JDK. There is actually prior art in JSRs. JSR 305: Annotations for Software Defect Detection Used @Nonnull. In normal circumstances, we would expect this annotation and

Objects.nonNull()

2011-01-13 Thread Brian Goetz
* and constructors, as demonstrated below: * blockquotepre * public Foo(Bar bar) { * this.bar = Objects.nonNull(bar); * } * /pre/blockquote * * @param obj the object reference to check for nullity * @param T the type of the reference * @return {@code

Re: Objects.nonNull()

2011-01-13 Thread Tom Hawtin
On 13/01/2011 20:06, Brian Goetz wrote: Most of the other methods in this class are of the form do the right thing if the object is null (or an array), but this one is throw an exception if the object is null. The intent is clear -- it is for simplifying fail-fast behavior by checking for

Re: Objects.nonNull()

2011-01-13 Thread Paul Benedict
Maybe you have a nonNull() that throws NPE, and a nonNullSafe() ? On Thu, Jan 13, 2011 at 3:12 PM, Tom Hawtin tom.haw...@oracle.com wrote: On 13/01/2011 20:06, Brian Goetz wrote: Most of the other methods in this class are of the form do the right thing if the object is null (or an array),

Re: Objects.nonNull()

2011-01-13 Thread Rémi Forax
On 01/13/2011 11:11 PM, Brian Goetz wrote: rathole I disagree with Tom here. We have *already* made the billion dollar mistake, and we can't eliminate that headache (but we can provide easier access to aspirin.) Java developers are *constantly* writing methods like the suggested

Re: Objects.nonNull()

2011-01-13 Thread Brian Goetz
and public staticT T nonNull(String obj) { return (obj == null) ? : obj; } etc. I don't know, this doesn't feel right to me. It would probably make more sense to have a: public static T T defaulted(T test, T defVal) { return test == null ? defVal : test; } This would cover both of the above

Re: Objects.nonNull()

2011-01-13 Thread Ulf Zibis
Am 13.01.2011 23:31, schrieb Rémi Forax: I think I prefer throwIfNull() which is explicit. +1 -Ulf

Re: Objects.nonNull()

2011-01-13 Thread David M. Lloyd
On 01/13/2011 04:31 PM, Rémi Forax wrote: On 01/13/2011 11:11 PM, Brian Goetz wrote: rathole I disagree with Tom here. We have *already* made the billion dollar mistake, and we can't eliminate that headache (but we can provide easier access to aspirin.) Java developers are *constantly* writing

Re: Objects.nonNull()

2011-01-13 Thread mark . reinhold
Date: Thu, 13 Jan 2011 17:11:37 -0500 From: brian.go...@oracle.com ... One last question for Mark on the ensureXxx() convention: methods like ensureXxx() sometimes mean make this true (like ensureCapacity() in collections implementations) rather than barf if it is not true. Right.

Re: Objects.nonNull()

2011-01-13 Thread David Holmes
Rémi Forax said the following on 01/14/11 08:31: I think I prefer throwIfNull() which is explicit. +1 As to what gets thrown, none of these suggestions make that obvious from their name so I would not be concerned about that. Every Java programmer is very early introduced to

Re: Objects.nonNull()

2011-01-13 Thread Rémi Forax
On 01/13/2011 11:41 PM, David M. Lloyd wrote: On 01/13/2011 04:31 PM, Rémi Forax wrote: On 01/13/2011 11:11 PM, Brian Goetz wrote: rathole I disagree with Tom here. We have *already* made the billion dollar mistake, and we can't eliminate that headache (but we can provide easier access to

Re: Objects.nonNull()

2011-01-13 Thread Ulf Zibis
Am 13.01.2011 23:38, schrieb Brian Goetz: People use these to simplify cases like if (foo != null) for (Foo f : foo) { ... } to for (Foo f : nonNull(foo)) { ... } To be honest, I don't understand the real value of nonNull(). If the argument is null, NPE would be thrown anyway. Do I

Re: Objects.nonNull()

2011-01-13 Thread David M. Lloyd
On 01/13/2011 05:36 PM, David Holmes wrote: Brian Goetz said the following on 01/14/11 09:15: to go either way (both checkNonNull and ensureNonNull better match the actual behavior of the method than plain nonNull) but we might as well pick the right convention. Rémi's throwIfNull(x)

Re: Objects.nonNull()

2011-01-13 Thread mark . reinhold
Date: Thu, 13 Jan 2011 18:15:30 -0500 From: brian.go...@oracle.com ... Between checkNonNull() and throwIfNull(), I lean towards the former. In any case the answer should be driven by what is more obvious to the reader. Agreed.

Re: Objects.nonNull()

2011-01-13 Thread Rémi Forax
On 01/14/2011 01:20 AM, mark.reinh...@oracle.com wrote: Date: Thu, 13 Jan 2011 18:15:30 -0500 From: brian.go...@oracle.com ... Between checkNonNull() and throwIfNull(), I lean towards the former. In any case the answer should be driven by what is more obvious to the reader. Agreed.

Re: Objects.nonNull()

2011-01-13 Thread David Schlosnagle
On Thu, Jan 13, 2011 at 7:06 PM, Brian Goetz brian.go...@oracle.com wrote: For clarification only (we're not suggesting adding these NOW, but instead preserving the option): People constantly write methods like  public String nonNull(String s) { return s != null ? s : } and other versions

Re: Objects.nonNull()

2011-01-13 Thread Brian Goetz
I'm still troubled by the check prefix, though. It implies that the named condition will be tested but it doesn't clearly relate the result of that test to the method's exception-throwing behavior. Here's an idea: Why not treat this as a (degenerate) kind of conversion operation? Call it

Re: Objects.nonNull()

2011-01-13 Thread Ben Manes
wouldn't expect either style to be part of the core language. From: Brian Goetz brian.go...@oracle.com To: mark.reinh...@oracle.com Cc: core-libs-dev@openjdk.java.net Sent: Thu, January 13, 2011 4:52:27 PM Subject: Re: Objects.nonNull() I'm still troubled

Re: Objects.nonNull()

2011-01-13 Thread Brian Goetz
@openjdk.java.net *Sent:* Thu, January 13, 2011 4:52:27 PM *Subject:* Re: Objects.nonNull() I'm still troubled by the check prefix, though. It implies that the named condition will be tested but it doesn't clearly relate the result of that test to the method's exception-throwing behavior

Re: Objects.nonNull()

2011-01-13 Thread Tom Hawtin
On 13/01/2011 22:11, Brian Goetz wrote: rathole I disagree with Tom here. We have *already* made the billion dollar mistake, and we can't eliminate that headache (but we can provide easier access to aspirin.) Java developers are *constantly* writing methods like the suggested carpet-sweeping