Arguments that are passed into a method call in the wrong order can lead to hard-to-spot bugs in code. When these method parameters are of the same type, the compiler will not warn you that you have passed them in the wrong order, and no static analysis tool currently highlight this issue.
This IntelliJ plugin adds a new code inspection under Java > Probable Bugs: Parameters should be passed in the correct order
Running a code analysis on you project with this inspection enabled will highlight places where you may be passing parameters in the wrong order.
You have a method:
public void insert(String firstName, String lastName) {
db.savePerson(firstName, lastName);
}
However, in one part of your code, you have accidentally passed the arguments in the wrong order:
insert(lastName, firstName);
The compier will not complain, because both arguments are the same type: String
.
Running a code analysis with this plugin installed will warn that you are passing arguments in the wrong order.
In IntelliJ, go to Preferences > Plugins, and search for Method Parameter Order Inspection. Click on install and restart the IDE.
- Next, right click on the project you want to analyse, and select Analyse > Inspect Code....
- Click on the 3 dot menu under the Inspection profile section.
- Search for "Parameters should be passed in the correct order", and ensure the checkbox beside it is ticked.
- Dismiss the "Inspections" dialog, and run the inspection by clicking "OK".
If you would rather try this plugin without first installing it in your IntelliJ IDE, you can download this code and run:
./gradlew runIde
This will start an IntelliJ Community Edition IDE where you can try out the plugin without changing your standard IntelliJ intall.