Inspectopedia 2025.2 Help

Bulk 'Files.readAttributes()' call can be used

Reports multiple sequential java.io.File attribute checks, such as:

  • isDirectory()

  • isFile()

  • lastModified()

  • length()

Such calls can be replaced with a bulk Files.readAttributes() call. This is usually more performant than multiple separate attribute checks.

Example:

boolean isNewFile(File file, long lastModified) throws IOException { return file.isFile() && file.lastModified() > lastModified; }

After the quick-fix is applied:

boolean isNewFile(File file, long lastModified) throws IOException { var fileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); return fileAttributes.isRegularFile() && fileAttributes.lastModifiedTime().toMillis() > lastModified; }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

BulkFileAttributesRead
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Performance

This inspection does not show a warning if IOException is not handled in the current context, but the quick-fix is still available.

Note that the replacements are usually not completely equivalent and should be applied with care. In particular, the behavior could differ if the file does not exist at all.

This inspection only reports if the language level of the project or module is 7 or higher.

New in 2022.1

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection BulkFileAttributesRead

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025