LexicographicalPermitsListing

SUGGESTION

Style

View source code on GitHub

Summary

Sort permitted subtypes lexicographically where possible

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("LexicographicalPermitsListing") to the enclosing element.

Disable this pattern completely by adding -Xep:LexicographicalPermitsListing:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

 interface A {
   non-sealed class X extends UnsortedPermitsClass implements UnsortedPermits {}
 
   non-sealed class Y extends UnsortedPermitsClass implements UnsortedPermits {}
 
   non-sealed class Z extends UnsortedPermitsClass {}
 
-  sealed interface UnsortedPermits permits Y, X {}
+  sealed interface UnsortedPermits permits X, Y {}
 
-  sealed class UnsortedPermitsClass permits Z, X, Y {}
+  sealed class UnsortedPermitsClass permits X, Y, Z {}
 }
 

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

interface A {
  non-sealed class X extends UnsortedPermitsClass
      implements SinglePermits, SortedPermits, UnsortedPermits {}

  non-sealed class Y extends UnsortedPermitsClass implements SortedPermits, UnsortedPermits {}

  non-sealed class Z extends UnsortedPermitsClass {}

  sealed interface NoPermits {
    record R() implements NoPermits {}
  }

  sealed interface SinglePermits permits X {}

  sealed interface SortedPermits permits X, Y {}

  // BUG: Diagnostic contains:
  sealed interface UnsortedPermits permits Y, X {}

  // BUG: Diagnostic contains:
  sealed class UnsortedPermitsClass permits Z, X, Y {}
}

Copyright © 2017-2026 Picnic Technologies BV