In this article we'll look at the main features of SonarQube - a platform for continuous analysis and measurement of code quality, and we'll also discuss advantages of the methods for code quality evaluation based on the SonarQube metrics.
SonarQube is an open source platform, designed for continuous analysis and measurement of code quality. SonarQube provides the following capabilities:
Nowadays a lot of projects are opening their source code and letting those who are interested in the development of it edit the code. OpenJDK is no exception, programmers PVS-Studio have found a lot of interesting errors that are worth paying attention to.
OpenJDK (Open Java Development Kit) - a project for the creation and implementation of Java (Java SE) platform, which is now free and open source. The project was started in 2006, by the Sun company. The project uses multiple languages- C, C++, and Java. We are interested in the source code written in C and C++. Let's take the 9th version of OpenJDK. The code of this implementation of Java platform is available at the Mercurial repository.
During verification, the analyzer found different errors in the project including: copy-paste, bugs in the operation precedence, errors in logical expressions and in pointer handling and other bugs, which are described in detail in this article.
It's always amusing to check a project which is used and maintained by a large number of people. The better and more accurate the code is, the more safely and effectively the program will work. Those bugs we found, are another proof of the usefulness of an analyzer, as it allows the detection of such errors which would otherwise be hard to detect doing simple code review.
Do you know how much memory the string has? I have heard all kinds of answers to this question, ranging from "do not know" to "string has 2 bytes". Here are some more questions: How much space does empty string take? How much space does the class object of Integer take? How much space will take your own class object with three Integer fields? It is funny, but none of my Java programmer friends could answer these questions ... Most of us do not need it, and nobody will think about it in the real java projects. After all, this is the same as you would not know the engine capacity of vehicle that you drive every day. You can be a great driver and did not even know what 2.4 or 1.6 means on your car. But I am sure that there are few people who are not familiar with the meaning of these numbers. So why do java programmers know so little about this part of their tool?
Integer vs int
We all know that in java - everything is an object. Except, perhaps, primitives and references to the objects themselves. Let us consider two typical situations:
This article explains how to implement some data structures in Java. It will be useful for beginners that use a programming language Java, as well as those who already know how to write a new ArrayList (), but have little knowledge what is happening inside.
Let us talk about the ArrayLists
ArrayList implements the List interface. As we know, Java arrays have a fixed length, and after the array is created, it cannot increase or decrease. ArrayList can change its size at runtime, but it does not necessarily indicate the size when an object is created. The elements of ArrayList can be any types, including null.