<div dir="ltr"><div>`new ArrayList<>(Arrays.asList(array))` is quite complex syntax to convert an array to an java.util.ArrayList,<br></div><div>so a suggestion could be to add a new method to Arrays to convert an array to a normal java.util.ArrayList which is modifiable.<br></div><div><br></div><div>Are there any low-hanging-fruit issues in core-libs-dev in <a href="http://bugs.openjdk.org">bugs.openjdk.org</a> that you are aware of that <br>you would like me to help you implement?<br></div><div><br></div><div>Thanks for considering my request.</div><div><br></div><div>Regards,<br></div><div>Andreas</div><div><br></div><div><br></div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 18, 2022 at 5:51 PM Daniel Fuchs <<a href="mailto:daniel.fuchs@oracle.com">daniel.fuchs@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Andreas,<br>
<br>
First of all, congratulations for seeking advice before working on<br>
a PR. This is exactly how first contributions should start. Thank<br>
you for that!<br>
<br>
Given the area in which you intended to work however, `core-libs-dev`<br>
might have been a better list than `discuss` to start from.<br>
<br>
With regard to the meat of the issue however, and as noted by Ethan,<br>
Arrays.asList() behaves as intended, and changing that would be a<br>
major incompatible change, as many users of the API expect the list<br>
returned by Arrays.asList to be immutable (and depend on it).<br>
It is not possible nor desirable to change that.<br>
<br>
As for your observation, I believe that:<br>
<br>
`new ArrayList<>(Arrays.asList(array))`<br>
<br>
will get you what you want.<br>
<br>
best regards,<br>
<br>
-- daniel<br>
<br>
On 18/11/2022 16:29, Andreas Røsdal wrote:<br>
> Yes, the exception comes when adding objects to the returned list. So I <br>
> would like a convenient way to use Arrays to convert an array to a <br>
> normal modifiable java.util.ArrayList, instead of this AbstractList.<br>
> <br>
> <br>
> On Fri, Nov 18, 2022 at 5:23 PM Ethan McCue <<a href="mailto:ethan@mccue.dev" target="_blank">ethan@mccue.dev</a> <br>
> <mailto:<a href="mailto:ethan@mccue.dev" target="_blank">ethan@mccue.dev</a>>> wrote:<br>
> <br>
> What situation were you encountering the exception? Was it when<br>
> trying to add to the returned list?<br>
> <br>
> If so, that's expected. Arrays.asList only wraps an underlying<br>
> array, it can't grow it. By that measure List.of() is even more<br>
> unintuitive because you can't set anything.<br>
> <br>
> On Fri, Nov 18, 2022, 11:06 AM Andreas Røsdal<br>
> <<a href="mailto:andreas.rosdal@gmail.com" target="_blank">andreas.rosdal@gmail.com</a> <mailto:<a href="mailto:andreas.rosdal@gmail.com" target="_blank">andreas.rosdal@gmail.com</a>>> wrote:<br>
> <br>
> Hello!<br>
> <br>
> I am an aspiring JDK contributor, having used Java in my work as<br>
> a developer.<br>
> <br>
> I was recently surprised by an Exception thrown when using the<br>
> java.util.Arrays.asList() method<br>
> so I would like to propose some improvements to this API. In<br>
> particular:<br>
> - When using java.util.Arrays.asList() then AbstractList is<br>
> throwing UnsupportedOperationException which is not<br>
> user-friendly or intuitive.<br>
> - java.util.Arrays.asList() returning a private class called<br>
> ArrayList, which is not the usual java.util.ArrayList, so it's<br>
> not user-friendly or intuitive.<br>
> <br>
> Since this would be my first contribution to the JDK, and the<br>
> goal is to complete the contribution with accepted pull request<br>
> and get the Arrays API improved, what would the first step to<br>
> making this first improvement to the JDK be?<br>
> <br>
> I would also like to share a link to an open source project I've<br>
> been working on:<br>
> <a href="https://github.com/fciv-net/fciv-net" rel="noreferrer" target="_blank">https://github.com/fciv-net/fciv-net</a><br>
> <<a href="https://github.com/fciv-net/fciv-net" rel="noreferrer" target="_blank">https://github.com/fciv-net/fciv-net</a>><br>
> <br>
> Thank you!<br>
> <br>
> Regards,<br>
> Andreas R.<br>
> <br>
<br>
</blockquote></div></div>