Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8355753

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 25
    • tools
    • None
    • jdk-25+20-19-ge01e33d19b9

    • 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").

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: