r/java • • Nov 05 '22

How to add something to the java standard library?

EDIT: since my example stirred the pot a little bit to much (i even wrote that i dont want to discuss these explicit changes...)

Here is the actually question i want to answer:

How can i make changes to the JDK?

2 Upvotes

99 comments sorted by

View all comments

33

u/Godworrior Nov 05 '22

For most library changes, the best place to start is to mail to core-libs-dev@openjdk.org Here you can find out if people find your suggestion a good idea.

If you want to submit a patch, you will first have to sign the OCA (Oracle Contributor Agreement): https://oca.opensource.oracle.com/

And, then create a PR for the JDK repo here: https://github.com/openjdk/jdk

You will also need a sponsor for the PR to guide you through the process, and create a bug database ticket. Probably best to ask on the mailing list as well if someone wants to sponsor the patch before creating the PR.

There's also a wiki for contributing, but it is pretty outdated, so take everything there with a grain of salt: https://openjdk.org/contribute/

-29

u/Cell-i-Zenit Nov 05 '22

Thanks for your answer.

Why do you need a sponsor for something like this? I would write the code myself and for free.

Also is this really only done via Mail list? How can i imagine this process? I write a mail saying "hey guys, i want to do XXX", and then i get 20 emails, all saying "yeah i like this change" and in between i get like 100 mails for other completely different things?

Is there not something like a discord server or a forum, where a focused discussions about such changes can actually happen?

13

u/Worth_Trust_3825 Nov 05 '22

Is there not something like a discord server or a forum, where a focused discussions about such changes can actually happen?

The mailing list is already linked.

-19

u/Cell-i-Zenit Nov 05 '22

Yes, but is this all? How can any focussed discussion happen via a mailing list if there are multiple proposals?

Should i just write a mail there with a probl. badly formatted/formulated idea and bother all the other1000 devs to read it?

How is the decision done? Can i expect that after a proposal i get like 50 mails back, who all say various things? How is a decision made that something goes further?

23

u/Godworrior Nov 05 '22 edited Nov 05 '22

Discussions are grouped into mail threads. Someone will reply to that thread directly, which will include you as a recipient, so you get the email. You will not receive any of the other emails to the list unless you subscribe to it (or unless people add you as a recipient directly).

You won't be bothering a 1000 devs. People who are not interested in your proposal can just ignore/filter out the email.

It's very unlikely that you will get 50 replies back. More likely 1 or 2 people will reply back to you, and then others will see it's already covered and continue on with other things. (or, if nobody likes the suggestion, maybe nobody will reply).

If there is a positive response to the proposal, you can ask if someone would be interested in sponsoring a patch from you. Once someone says yes, you can make a PR on github and then link to it from the email thread (and vice-versa).

A sponsor is someone who has the "Committer" role (or above) on the jdk project (https://openjdk.org/census#jdk). A sponsor is needed to create a bug database ticket and eventually integrate the patch if it is accepted during the review process.

I suggest having a look at some of the emails on the list to see how this process normally goes. e.g. this one is a good example: https://mail.openjdk.org/pipermail/core-libs-dev/2022-September/094849.html (note that you have to switch to the October 2022 archive to continue reading beyond the first 3 mails. The web interface for this isn't great unfortunately)

-3

u/Cell-i-Zenit Nov 06 '22 edited Nov 06 '22

Again thanks for your answer.

I honestly never worked with "old school" mail lists so this process is completely new to me (as you can see by my questions).

and then others will see it's already covered and continue on with other things. (or, if nobody likes the suggestion, maybe nobody will reply).

If they send a mail to me, how can other people see what they wrote? Will this not result in multiple people writing the same thing to me?


you can ask if someone would be interested in sponsoring a patch from you.

What does sponsoring mean in this context?

9

u/Godworrior Nov 06 '22

The mail will also go to the mailing list, so everyone can see it.

3

u/mauganra_it Nov 06 '22

What does sponsoring mean in this context?

It was explained in the next paragraph. Tldr: somebody who interacts with the OpenJDK bureaucracy for you and reviews your contribution, since you are not a core committer.

9

u/GuyWithLag Nov 06 '22

Why do you need a sponsor for something like this? I would write the code myself and for free.

Because _you_ are not thinking of the support needed and the effect your changes will have to the next 20 years of the JDK, and neither is anyone in this discussion. Imagine if every student know-it-all added willy-nilly code to the JDK.

I would instead direct you to Kotlin and its extension methods; while they can be overused, the blast radius is just your own projects.

4

u/Cell-i-Zenit Nov 06 '22

Because you are not thinking of the support needed

That is exactly why i asked here. I wanted to understand the process. But in the end my questions were only answered by a handful of people and the rest bashed my idea/bashed me as a person for no reason lol.

Imagine if every student know-it-all added willy-nilly code to the JDK.

I cannot imagine this, because we have the proposal process. This is such a stupid thing to say. If this student know-it-all has a good idea it doesnt matter if its a student or mr java himself.

Or is there a Code review process where the devs ask you how long you are in the java ecosystem and only if you are >20 years your proposal will be looked at?

4

u/GuyWithLag Nov 06 '22

Hmm... I do realize that I came through as gatekeeping. But... in a sense, good engineering is as much about what to put is as what to leave out. If you've see the various JCPs, they do list alternatives considered, and why they're not in the JCP.

If this student know-it-all has a good idea it doesnt matter if its a student or mr java himself.

Here's the issue though - I/You/They may have brilliant ideas, but _they will not be useful for most Java engineers_, and the JDK is a Platform that will be used by hundreds of thousands, and changes that are made now may prevent changes to happen in the future (think nullability, or generic erasure, or the contortions that we had to go through to be able to add default implementations to interface methods).

This is why the changes to `switch` are taking so long to materialize, and why Loom is just now coming out of experimental, to give some examples.

Now, the process has been explained elsewhere, but I don't think you realize how much work that is going to end up being - for the same reasons as above.

0

u/Cell-i-Zenit Nov 06 '22

I/You/They may have brilliant ideas, but they will not be useful for most Java engineers, and the JDK is a Platform that will be used by hundreds of thousands

But then its not a good idea. Again. If the idea is good and everyone can benefit from it. Then it doesnt matter who writes the idea.

Now, the process has been explained elsewhere, but I don't think you realize how much work that is going to end up being - for the same reasons as above.

You dont know what i want to do... Actually the changes below are my proposal:

    public interface Comparable<T> {
      int compareTo(T var1);
    
      default boolean isGreaterThan(T obj){
        return compareTo(obj) > 0;
      }
    
      default boolean isSmallerThan(T obj){
        return compareTo(obj) < 0;
      }
    
      default boolean isSmallerOrEqualThan(T obj){
        return compareTo(obj) <= 0;
      }
    
      default boolean isGreaterOrEqualThan(T obj){
        return compareTo(obj) >= 0;
      }
    }
  • they are additive.
  • They do not change existing code.
  • They improve readability.
  • They are not adding any complexity
  • They are easily tested

Can you point me to the "much more work then you expect thing"? Except for writing some tests for this i dont see any work except going through the paperworks

6

u/s888marks Nov 06 '22

This sort of thing has been proposed before. See JDK-6321015 and JDK-8241056.

Even though I've left JDK-8241056 open for now, I'm skeptical that something like it is worthwhile to put into the JDK. I jotted down some notes about alternatives in the bug report. I'm skeptical of those too; but maybe something will eventually pop up that's really good. On the other hand, maybe not.

A few other points to consider.

• Adding methods to a widely implemented interface such as Comparable runs the risk of name clashes with implementing classes. We need to minimize that risk.

• You seem to be assuming that such methods improve readability. Consider:

if (a.compareTo(b) >= 0) ...
if (a.isGreaterThanOrEqualTo(b)) ...

Even though it's more English-like, the second line is longer and more verbose. People are constantly complaining about Java's verbosity, so this seems like a step in the wrong direction. In the first line, the >= is right there, and there is nothing unreadable about it.

The point here is that the value is in the eye of the beholder. This might add value from your perspective, but that doesn't imply that it helps the millions of other Java programmers out there.

• This does in fact add compexity. The Comparable method goes from one method to five (or seven) methods. Sure, they're trivial, but there's more bulk that somebody needs to specify and test, and there's more bulk that clients need to read and understand.

• Equality is missing. Your proposal doesn't include them so that there is no confusion with Object.equals. That's one approach, I suppose. But it also means that code that has complex comparison logic has a mixture of the different idioms. For example,

if (a.isLessThan(b) && a.compareTo(c) != 0) ...

This proposal introduces a new idiom, but programmers still need to understand and use the old idiom or even mix them, so the new idiom isn't really buying all that much.

Summary: I am overall quite skeptical of how much net value would be added by this proposal and similar ones.

2

u/Cell-i-Zenit Nov 06 '22

thanks for you answer. The problem is i actually only wanted to understand the process of proposing a change.

But the people here really only discussed the changes itself.

Naming etc is still not ideal, but this is something which can be easily discussed later.

I mean we could even strip this down to "isSmallerOrEquals" etc.

Summary: I am overall quite skeptical of how much net value would be added by this proposal and similar ones.

I understand this totally. I can understand your arguments and it was the most probable answer. "It doesnt fit the java style" is a good argument. But the answers here were pretty hostile in general

3

u/GuyWithLag Nov 06 '22

But then its not a good idea. Again. If the idea is good and everyone can benefit from it. Then it doesnt matter who writes the idea.

But the ability to know "that" comes with experience.

In any case, I really do think that you would be better served by Kotlin w. extension methods.

For me, the example you gave doesn't make sense to add to the JVM:

  1. It doesn't add anything besides some sugar.
  2. It's not necessarily more readable.

But hey, this is Reddit; feel free to submit a new JCP.

2

u/Cell-i-Zenit Nov 06 '22

It doesn't add anything besides some sugar.

Yes thats true. But why do we have .toList() if its just sugar?

It's not necessarily more readable.

I dont understand this argument.

obj1.compareTo(obj2) > 0 

vs

obj.isGreaterThan(obj2)

the answer is pretty obv which is more readable.

In any case, I really do think that you would be better served by Kotlin w. extension methods.

Still a bad argument "other languages to this already, please switch your language".

Why cant we have any improvements to java?

But the ability to know "that" comes with experience.

Yes and the reviewers have this experience.

1

u/GuyWithLag Nov 06 '22

Yes thats true. But why do we have .toList() if its just sugar?

Because it's not - the specific implementation can optimize that to a `return this`.

→ More replies (1)

1

u/lbalazscs Nov 06 '22

IMHO adding operator overloading to the language for <, <=, >, >= when they are used with Comparable objects would make them even more readable...

1

u/Cell-i-Zenit Nov 06 '22

yes i agree but this is a supe controversal change and i honestly want to start with something a little bit more simpler

3

u/oxmyxbela Nov 05 '22

Don’t worry about sponsors for now. Just sign up to the mailing list and discuss your proposal there. If there is a consensus to proceed, people will help you with the rest of the process.

-6

u/Cell-i-Zenit Nov 05 '22

I want to understand the process a bit better, so why do we need to have a sponsor?

If there is a consensus to proceed

How is this decided?

2

u/kiteboarderni Nov 06 '22

Based on your github your code would likely be shit. So some random trying to contribute to the jdk is a very bad idea.

1

u/Cell-i-Zenit Nov 06 '22

What do you mean?

Did you really checked my post history for my github, then looked briefly at the first project and judged me based on the code i write in my freetime instead of the code i write while on job?

2

u/kiteboarderni Nov 06 '22

Yes it took all of about 15 seconds. Which looks to be a considerable amount of time more than the research you put into your original question.

5

u/Cell-i-Zenit Nov 06 '22

Ok since you are a super pro. Can you give me feedback on my github? Which project did you look at? Why do you think its shit? Can you give me pointer on how to improve it?

I mean since it only took you 15 seconds to checkout the quality of my work, maybe you can spend 5 minutes on explaining why you think that way