1

It is difficult to contribute code to an open source project, especially a well-known project like Spring , at least that's what Fat Brother thinks. Sometimes our inspiration may not match the author's design intent, even if your code is elegant.

I once submitted an optimization to Spring Security that I think is very important, and I have communicated with the author dozens of times and couldn't convince him. People say that there is an abstract interface. If you think you don't want to implement one for yourself, the default is to use it. I have no choice but to give up this PR .

Unexpectedly, in Spring Authorization Server , I seized an opportunity to be absolutely accepted. After more than a month of waiting, my PR was finally accepted.

When I was writing Spring Authorization Server related tutorials, when I called the authorization server meta-information endpoint, I accidentally put an anchor symbol # , similar to http://issuer.felord.cn/# , and reported a request error, in When tracing the source code, I found that the url has been verified, and this unexpected result shows that there must be loopholes in the rules. So I checked the definition of the relevant RFC and found the basis for RFC8414 .

There is no technical content in the implementation of this specification. If I tell you, you can do it, even better than me, so as long as it is implemented, it should be impossible for PR to be accepted, and you can even open champagne half-time. This optimization will be implemented in version 0.3.0 . For this process, I briefly summarize and share it, which may be helpful to you who want to participate in open source contributions.

code style

The first is the code style. Open source projects all have some code style requirements. I have imitated (copied) Spring 's design in many things before, so I paid special attention to this when implementing the specification. The naming style, indentation, etc. are repeated repeatedly. scrutinize.

Understand the architectural thinking of the project

During the whole PR process, the main problems I have come up with are here. While my initial implementation performed fine and was completely within the lifecycle, it was clearly not in the best position. For example, you can write the verification of parameters in the control layer or in the service layer. The result must be no problem, but there may be problems in the process. The author communicated with me and showed his design ideas, and I quickly corrected the problem.

Unit testing is very important

The implementation code is really not much, the unit test code is almost 20 times larger. We usually write main the method is simple sout print it and it's done, but it is different for open source projects. Especially this well-known open source framework requires you to test every aspect of your implementation. If you want to contribute code to open source projects, you must know common assertions and Mock instrumentation. This fat brother's blog felord.cn has related introductions.

Git specification

Git commit specification Fat Brother has also emphasized its importance many times, and it is also a basic requirement to follow some commit specifications in large open source projects. You should also be familiar with the rules of some Pull Requests and the code review process. These efforts are all in daily life. You have to be proficient with Git . Spring requires minimal functional submission, how to say it? Your implementation must be a complete unit of minimal granularity, you cannot have both enhances and new features in one commit. And your commits must be squashed into a single git commit , even if pushed back for revision. to use more

 git commit --amend -m '你的提交信息'

In some last resort, git rebase and squash commits may help you.

But don't go to the bottom of the Git principle, it is enough to use the tools proficiently.

Be good at discovering, dare to act

The most important point is that you have to be good at finding it. For example, the following bug (which has not been completely fixed yet), if I say it is a bug, you will be shocked. I was the same at the time.

 public DefaultSecurityFilterChain(RequestMatcher requestMatcher, List<Filter> filters) {
        if (!filters.isEmpty()) {
            logger.info(LogMessage.format("Will not secure %s", requestMatcher));
        }
        else {
            logger.info(LogMessage.format("Will secure %s with %s", requestMatcher, filters));
        }
        this.requestMatcher = requestMatcher;
        this.filters = new ArrayList<>(filters);
    }

The log logic of version 3.1 is actually wrong to version 5.6 ! To fix it, you only need to change the location, and my mother should also change this bug . But no one found and questioned it until recently someone submitted a fix ( version 5.7 will fix this bug ).

So you have to be good at discovering some problems and details, and at the same time dare to question, even if the question is wrong, you will not lose anything.

have expertise

Like everyone else, I usually learn everything, but I can't help it! Being an original technology blogger is too easy for content anxiety. But I have deliberately guaranteed some things to learn in-depth, some things must become your unique skills, and you need to specialize in many things, so that you may have more opportunities in the field of expertise.

TODO

Becoming an open source contributor is just the beginning, more challenges lie ahead. Some people ask me why I have less articles recently! Here's what I've been doing recently.

First of all, because of the epidemic, I was isolated and working from home.

Second, there are several open source contributions in progress.

Also, I am working on an open source project Id Server based on Spring Authorization Server . You can think of it as a minimalist version of keycloak . Even the initial function is relatively simple, layui is learned first, and I can't do well in the interface. Take a screenshot.

It's challenging to do this stuff, the front end is so hard! At present, it has taken shape, and a preview version will be released in the near future. Students are also welcome to participate and contribute.

关注公众号:Felordcn 获取更多资讯

Personal blog: https://felord.cn


码农小胖哥
3.8k 声望8k 粉丝