IntelliJ IDEA 2023.3 Help

Customize views

During a debugging session, IntelliJ IDEA shows you information about your variables, classes, threads, frames, and more. Moreover, the debugger offers a range of options to customize the display of data according to your project's needs.

By default, IntelliJ IDEA presents a well-organized and comprehensive view of debugging details in the Debug tool window. This layout provides you with the most commonly used options and actions.

However, you may want to examine some specific details or have the data filtered or rendered in a specific format. In this scenario, IntelliJ IDEA lets you customize the default layout of the Debug tool window. You have the flexibility to create a powerful and granular configuration, ensuring that your classes are displayed according to your preferences.

Customize threads view

You can customize how threads are displayed on the Frames and Threads tabs. It might be helpful when you are working on a multithreaded application and often need to access information about your threads.

  • Right-click anywhere in the Frames or Threads tab and select Customize Threads View.

    Customize Threads View item in the menu

Item

Description

Show thread groups

If this option is selected, threads appear in a hierarchy of thread groups. Having a tree-like hierarchy is useful when your program manages a number of similar threads in groups. Also, the option separates system threads from the user-defined ones, making it easier to navigate in the list.

In order for a thread to appear in a particular group, use java.lang.ThreadGroup in your program.

Show stack frames for synthetic methods

Specify whether you want to see stack frames for synthetic methods (the methods introduced by the compiler, which are not present in the source code). An example of such method is a method created by an inner class so that the enclosing class could access its private members.

Move current thread to the top

Keeps the current thread on top of the list (when Show thread groups is disabled).

Show line number

Shows the number of the line that is currently executed in a frame. This feature requires that the application is compiled with line number information.

Show class name

Shows the name of the class containing the method. When the code inside an anonymous inner class is executed, the name of the enclosing class is displayed instead, followed by a dollar sign and a number, for example: MyClass$1.

Keeping this option enabled is useful when you are dealing with inherited methods and there is a need to quickly differentiate between method implementations in subclasses.

Show package name

Shows the name of the package for classes. The code in the default package is not marked. This option is only active when Show class name is enabled. Use it when there is ambiguity that class name alone does not eliminate (like java.util.Date vs. java.sql.Date).

Show source file name

Shows the name of the source file for classes.

Show method arguments types

Shows the types of the arguments that a method takes. This is useful when dealing with overloaded versions of the same method.

Customize data view

IntelliJ IDEA allows you to configure which information about the variables you want to get. For example, you may choose to show/hide instance IDs or use the toString representation for viewing particular sets of classes.

Unless explicitly specified, these preferences apply to all the places where the variable values are displayed (the Variables tab, inline values view, tooltips, and so on).

Sort variables alphabetically

If required, you can enforce alphabetic ordering for items in the Variables tab.

  1. Press Ctrl+Alt+S to open the IDE settings and then select Settings | Build, Execution, Deployment | Debugger | Data Views.

  2. Select the Sort Variables Alphabetically option.

Configure automatic expression evaluation

The debugger analyzes the statement at the breakpoint and its nearest surrounding statements to find various expressions in the source code, such as myvar.myfield.

If they don't contain explicit method invocations, the debugger evaluates them and shows the corresponding values in the Variables view.

To disable automatic evaluation of expressions:

  1. Press Ctrl+Alt+S to open the IDE settings and then select Settings | Build, Execution, Deployment | Debugger | Data Views.

  2. Clear the Enable auto expressions in Variables view option.

Show/hide object types

You can select whether to display the type of the object for the corresponding reference-type variables.

  • Right-click anywhere in the Variables tab and turn Show types on/off.

The displayed type is the type of the actual object and not the type of the variable that holds the reference. If you want to toggle the visibility of the declared type, use the Declared type option in the Customize Data Views dialog.

Configure display of specific types

You can fine-tune how particular types are displayed.

The procedure and properties described here allow you to configure the basic built-in options that provide for the most cases. For custom configuration, refer to type renderers.

  • Right-click anywhere in the Variables tab and select Customize Data Views.

Item

Description

Autoscroll to new local variables

Automatically scrolls to new variables that appear in the scope when stepping.

Predict condition values and exceptions based on data flow analysis.

Enables editor hints for boolean expressions or exceptions that are known beforehand based on information from data flow analysis. For more information, refer to Inline variables view.

Show

  • Declared type: shows the type of the variable that holds the reference to the object.

  • Synthetic fields: shows synthetic fields (for example, compiler-generated fields of inner classes).

  • $val fields as local variables: shows outside variables used in anonymous classes as if they were local. Requires Synthetic fields.

  • Fully qualified names: shows fully qualified names for actual and declared types.

  • Object id: provides the ID of the particular instance, for example, java.util.ArrayList@798. For ID to be displayed, the Show Types option needs to be enabled.

  • Static fields: shows static fields in the Variables tab and tooltips.

  • Static final fields: shows static final constants in the Variables tab and tooltips. Requires Static fields.

Show type for strings

Shows type for java.lang.String instances. When disabled, this type can be identified by the enclosing double quotes.

Show hex value for primitives

Adds hexadecimal format for byte, short, int, long, and char types. When enabled, both decimal and hexadecimal formats are shown.

Hide null elements in arrays and collections

Excludes null references when displaying the contents of arrays and classes that implement Collection (not applicable to descendants of Map).

Auto populate Throwable object's stack trace

When the program is suspended after throwing an exception or error, its stack trace doesn't have any elements in it yet. For the stack trace to be populated, you have to call getStackTrace() on this Throwable. When Auto populate Throwable object's stack trace is enabled, IntelliJ IDEA does this for you.

Enable alternative view for Collection classes

Select this option to display contents of classes that implement Collection, Map, or List in a more convenient format (for example, to display each map entry as a key-value pair).

Enable toString() object view

Allows you to configure which classes use the result of toString() as their display value. When specified through fully qualified class names, this option applies to the descendants of these classes as well. You can also define a class pattern, using regular expressions syntax, for example:

  • *.Test: all classes called Test regardless of the package

  • javax.swing.*: all code in the javax.swing package and all its subpackages

  • ?est.Tes?: all classes starting with Tes followed by any letter in packages starting with any letter followed by est

  • *.T*: all classes starting with T in all packages

Custom type renderers

IntelliJ IDEA allows you to provide a completely custom display format for various objects during a debugging session. This can be achieved by using renderers. A renderer is a special setup associated with a particular type that controls how the instances of this type are displayed in the Debug tool window. This setup is based on custom expressions that provide high level of flexibility for displaying the data.

A renderer in action

Renderers support all types including primitives and arrays. Also, renderers disregard all access modifiers, so you can access any field irrespective of whether it is encapsulated.

In renderers, you can implement any transformations including sorting and reduction to produce the desired output. You can even utilize sun.misc.Unsafe to display the actual memory addresses during debugging (although this is not recommended).

Renderers are particularly useful when you are working with custom collections, whose contents aren't easily readable, and you need to identify their contents at a glance.

Add a renderer

  1. Right-click anywhere in the Variables tab and select Customize data views.

  2. Apply the changes and preview the updates in the Debug tool window and the editor.

  3. On the Java type renderers tab, click Alt+Insert and configure the newly created renderer as required.

  4. Apply the changes and preview the updates in the Variables view.

Renderer properties

Item

Description

Renderer name

The name of the renderer. This name is used for managing renderers and doesn't affect how actual data is displayed.

Apply renderer to objects of type (fully-qualified name)

The object type to which this renderer applies. Enter the fully qualified name of the class or click Browse the Browse button and choose the desired type from the list.

If the class uses generics, use raw types for them. Due to type erasure, the types inside the diamond operator have no effect in renderers.

When rendering a node

This option determines how an object itself is displayed:

  • Show type and object id: controls whether class name and instance ID are shown.

  • Use default renderer: displays the object as it would be displayed without this renderer. This is useful if you want to only customize the way the object's contents are displayed.

  • Use following expression: lets you use the return value of some expression for displaying the object. All method calls and member variable access are relative to the rendered instance.

    For example, this.getName() will use the result of the getName() getter for displaying the object.

    The On-demand option disables automatic evaluation of the expression and only calculates the result when you expressly request so.

When expanding a node

This option determines how the contents of an object are displayed when it is expanded.

  • Use default renderer: displays the node children as they would be displayed without this renderer. This is useful if you want to only customize the way the object itself is displayed.

  • Use following expression: lets you use the return value of some expression for displaying the contents of a node, for example, this.toArray(). The expression has to return an array of primitive or reference types. The elements of the returned array are used to represent the node children.

    Test if a node can be expanded (optional): adds an automatic check whether the node representing the object can be expanded. The check uses the specified boolean expression, for example !this.isEmpty(). The expression is called on the instance, and if it evaluates to true, the debugger makes the node expandable.

  • Use list of expressions: allows you to specify multiple expressions each providing its own representation of the object's children.

    The On-demand option disables their automatic evaluation and only calculates the result when you select a specific expression.

Append default children

Controls whether the fields of the object (that would be normally displayed when no renderer is specified) should appear along with the expression results. This option is only available with Use list of expressions.

Remove a renderer

  1. Right-click anywhere in the Variables tab and select Customize data views.

  2. On the Java type renderers tab, select the renderer that you are going to remove and click Delete. Then, apply the changes.

Mute renderers

You can temporarily disable renderers without removing them altogether:

  • To mute a single renderer, right-click anywhere in the Variables tab and select Customize data views. On the Java type renderers tab, clear the box against the renderer you are going to mute and apply the changes.

  • To mute all renderers, right-click anywhere in the Variables tab and select Mute Renderers.

When required, you can unmute the renderers using the same procedure.

Add a renderer using annotation

You can assign type renderers to your classes using IntelliJ IDEA's built-in annotations. While this approach doesn't provide centralized control over the renderers, it is very useful when you need to share them with your team members. Once configured, the renderer will apply to the class (and its subclasses) every time you debug the code that is using them.

  • On the line preceding the class declaration, add the @Renderer annotation, for example:

    import org.jetbrains.annotations.Debug.Renderer; @Renderer(text = "name", childrenArray = "courses.toArray()", hasChildren = "courses.isEmpty()") public class Student { private String name; private ArrayList courses; Student(String name, ArrayList courses){ this.name=name; this.courses=courses; } }

text()

Specifies the expression for displaying the rendered object.

childrenArray()

Specifies the expression for displaying the children of the rendered object. The return value of the expression has to be an array.

hasChildren()

Specifies the expression for checking whether the node should be expandable.

Productivity tips

Use renderers in big projects

While creating your own renderers takes some time, it will pay back if you are working with a big project where you spend a lot of time working with custom classes.

Implement sorting in renderers

The expression used for displaying node children returns an array. Since arrays are ordered, this allows you to implement sorting for otherwise unordered structures like HashMap. This is useful, for example, when you have a map of users and want to view them sorted by email address.

Last modified: 19 March 2024