

GitHub - alibaba/p3c: Alibaba Java Coding Guidelines pmd implements and IDE plug...
source link: https://github.com/alibaba/p3c
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Preface
We are pleased to present Alibaba Java Coding Guidelines which consolidates the best programming practices over the years from Alibaba Group's technical teams. A vast number of Java programming teams impose demanding requirements on code quality across projects as we encourage reuse and better understanding of each other's programs. We have seen many programming problems in the past. For example, defective database table structures and index designs may cause software architecture flaws and performance risks. Another example is confusing code structures being difficult to maintain. Furthermore, vulnerable code without authentication is prone to hackers’ attacks. To address these kinds of problems, we developed this document for Java developers at Alibaba.
For more information please refer the Alibaba Java Coding Guidelines:
Introduction
The project consists of 3 parts:
Rules
Forty-nine rules are realized based on PMD, please refer the P3C-PMD documentation for more detailed information. Four rules are implemented within IDE plugins (IDEA and Eclipse) as follows:
-
[Mandatory]
Using a deprecated class or method is prohibited.
Note: For example, decode(String source, String encode) should be used instead of the deprecated method decode(String encodeStr). Once an interface has been deprecated, the interface provider has the obligation to provide a new one. At the same time, client programmers have the obligation to check out what its new implementation is. -
[Mandatory]
An overridden method from an interface or abstract class must be marked with @Override annotation. Counter example: For getObject() and get0bject(), the first one has a letter 'O', and the second one has a number '0'. To accurately determine whether the overriding is successful, an @Override annotation is necessary. Meanwhile, once the method signature in the abstract class is changed, the implementation class will report a compile-time error immediately. -
[Mandatory]
A static field or method should be directly referred by its class name instead of its corresponding object name. -
[Mandatory]
The usage of hashCode and equals should follow:- Override hashCode if equals is overridden.
- These two methods must be overridden for Set since they are used to ensure that no duplicate object will be inserted in Set.
- These two methods must be overridden if self-defined object is used as the key of Map. Note: String can be used as the key of Map since these two methods have been rewritten.
Recommend
-
141
fw_error_www This site http://www.oracle.com/technetwork/java/seccodeguide-139067.html is experi...
-
100
ea-async - EA Async implements async-await methods in the JVM.
-
5
← All postsGuidelines for Java code reviewTips for Java developers to get a jumpstart on reviewing code.By Meenakshi on April 1, 2021Table of Conte...
-
6
If you write software for long enough you begin to develop instincts about the relative difficulty of different problems and some of those solidify into rules of thumb. The following are some of the guidelines that direct my work on a daily...
-
5
rust-coding-guidelines-zh Rust 编码规范 中文版 《Rust 安全编码规范》 初稿发布 2021-10-31 (V 0.1) 据了解...
-
5
CVRS C++ Coding Style Guidelines CVRS C++ Coding Style Guidelin...
-
7
What coding guidelines should be, and are there good examples of guidelines? advertisements What are some good examples of codin...
-
6
-
2
Extends vs Implements in JavaSkip to content
-
4
#Java #OpenJDK
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK