@SuppressWarnings("this-escape") not respected for indirect leak via field

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 25
    • Affects Version/s: 25
    • Component/s: tools
    • None
    • Environment:

      jdk-25+20-19-ge01e33d19b9

    • b26
    • generic
    • generic

      The "this-escape" warning logic fails to suppress a warning that should be suppressed by @SuppressWarnings("this-escape") when the warning happens via a field initializer, all analyzable primary constructors are annotated with @SuppressWarnings("this-escape"), and at least one analyzable non-primary constructor is not annotated with @SuppressWarnings("this-escape").

      Here's an example of that happening:

          public class ThisEscape {
          
              private final int foo = leak();
          
              public ThisEscape() {
                  this("");
              }
          
              @SuppressWarnings("this-escape")
              private ThisEscape(String s) {
              }
          
              public int leak() {
                  return 1;
              }
          }

          ThisEscape.java:4: warning: [this-escape] possible 'this' escape before subclass is fully initialized
              private final int foo = leak();
                                          ^
          1 warning

      The compiler currently reports a leak at "foo" but it shouldn't - the initialization of "foo" happens within the second constructor which is annotated with @SuppressWarnings("this-escape").

            Assignee:
            Archie Cobbs
            Reporter:
            Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: