Tips for Faster Debugging in IntelliJ
Abhinav Pandey
Posted on April 22, 2022
Top IntelliJ tricks to debug issues faster. (excluding the debugger)
Fold Logs
Running an application can produce a lot of console output. Most of it is not useful and comes from third party libraries. You can fold console output lines coming from these libraries. This will help you focus on the important information.
- Select the class name on the log line and right click
- Select "Fold lines like this".
It will open a window and add this class to the list of classes to fold. You can further edit this class name to a package name to fold all classes in that package.
Search With Google
You can trigger a Google search from anywhere in the IDE - code, console, log files, text files, etc.
For e.g., when you see an error in the logs,
- Select the piece of text you want to search
- Right click
- Search with Google.
While this is a trivial thing, it gets you to StackOverflow faster.
If you want to take this one step further and stop the monopoly, use the Smart Search plugin which lets you use custom search engines.
You can even search on StackOverflow directly and cut out the middleman.
Compare files with Clipboard
You can compare contents of a file with the content in the clipboard. This is useful in comparing files which are not part of version control.
This can also serve as a quick way to compare and merge two files.
A usual usage scenario is to compare configuration files.
Show Git History for a Piece of Code
You see a code, but you don't know what it does (or why it does what it does).
To get an idea, you need to know why the code was written and/or who wrote it.
Find it out using the Git history.
- Select the piece of code
- Right click
- Go to the Git section and select "Show history for selection".
This will list down all the old commits which included changes in the code.
Compare code with a working copy
Something worked in the past, but now it doesn't. A great way to debug it is to check the changes that have been made to it since then.
There are multiple ways to do this.
- Use the Git option "Compare with branch" and compare the current code to the code in a branch that worked fine.
- Use the Git option "Compare with Revision" and compare it to the code in a commit that worked fine.
- Compare entire current branch with another branch. This is useful to understand multiple changes together instead of looking at a small piece of code.
Local History
You can see the history of changes you made to a file in the local history. IntelliJ maintains a local history for each file (yes, even uncommitted code is safe).
This can be helpful when recovering from accidental deletions or to recover an intermediate state of a file.
For e.g. You made the code work, tested it and then went on to refactor it before committing. If the code doesn't work, you can recover the previous working state of the file from the local history or just compare it to understand what you did wrong.
More importantly, if you have any tips of your own, feel free to share them in the comments.
Posted on April 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.