Throwing exceptions from records

Brian Goetz brian.goetz at oracle.com
Mon Mar 9 21:12:29 UTC 2020



>> I think this discussion has largely run its course, and is 
>> threatening to stray outside of the bounds of what this list is for.
>
>
> I was told that amber-dev was for discussion of records. I guess there 
> was a miscommunication?

Yes, perhaps the confusion is over the nature of said "discussion". The 
charter of the -dev lists is for collaboration and discussion on the 
_development_ of features in OpenJDK, not "any discussion pertaining to 
records".   As mentioned, constructive experience reports are always 
welcome, but they need to stay within the bounds of relevance and 
constructiveness, and you've surely found the bounds of both, and you're 
being told to dial it back.

For the record, a good guideline for when a non-development-related 
comment is in bounds is: Is this telling the design or development team 
something they are unlikely to already know?  Reporting bugs almost 
always is; sharing concrete experience often is; undirected complaining 
about features or disagreement with specific decisions usually is not 
(we are already well aware that some people would prefer a different 
choice for nearly any decision), and complaining about process almost 
never is.  I realize interpreting these lines require judgment, so this 
is your notice that you've gone way over these lines.  (And, based on 
what's happened over on panama-dev, not your first notice, or even close.)

> No one has said otherwise nor has anyone layed down or linked to any 
> other design documents that say my use case is wrong or invalid. 

I think if you actually read what's been discussed on these lists, you'd 
see that there has been a significant amount of discussion on the 
"design center" for this feature, which could have informed your 
judgment about whether you were working with, or against, the grain of 
this feature.  (And others, who had been following, tried to suggest 
maybe you were holding it wrong -- and instead of thanking them or 
constructively engaging, you just argued and complained more.)  There is 
plenty of information out there, but it might take some work to find.  
(But not that much.)  Participating in the development is advanced 
stuff, and if you want to play, you have to suit up.  (Or, if you don't 
want to, that's fine -- but then please don't bother those who are doing 
the work.)

Turning to your code, I agree with Kasper's intuition that you are 
trying to use records for something they were not intended for.  The 
design center for records is (as has been stated many times) "nominal 
tuples".  Is `nvmlInit` effectively a tuple?  Are the state-based 
equals, hashCode, and toString methods a natural fit for the domain?  Is 
the canonical constructor enforcing any necessary invariants?  Are you 
getting any benefit _at all_ from declaring as a record?  I don't think 
so.  These are signs that this isn't the tool you are looking for.  
(BTW, you can use the compact form of the constructor here; you don't 
need to write out `this.x = x`.)  Or, perhaps you might consider whether 
records are helpful as the _implementation detail_ of your class, by 
wrapping a record with the API you actually want to expose?

I suggest you go off and think about this stuff for a few weeks, read 
what you can about the subject, and then if you still have questions, 
and can express them constructively, consider trying again.



More information about the amber-dev mailing list