Private methods are implicitly treated as final

Issue #210 resolved
Jesper Öqvist created an issue

ExtendJ 8.0.1-190-g8b2039e Java SE 8

While a private method can not be overridden, some analyses should not treat private methods as being final just because they are private.

For example, the test if a @SafeVarargs annotation is illegal uses the isFinal attribute. However, this makes ExtendJ not behave like javac which does not consider a private method as final for the @SafeVarargs usage. See JLS 7 § and issue #208.

In bytecode generation, the isFinal attribute should not be used for generating the ACC_FINAL flag. The javac output only includes ACC_FINAL when the final modifier is present (and not when the method is declared inside a final class).

The current definition of MethodDecl.isFinal() in java4/frontend/Modifiers.jrag:

  syn boolean MethodDecl.isFinal() =
      getModifiers().isFinal() || hostType().isFinal() || isPrivate();

Comments (1)

  1. Jesper Öqvist reporter

    MethodDecl.isFinal() only tests for final modifier

    The isFinal attribute on MethodDecl was too smart. It was used in situations where only the final modifier should have effect, allowing private methods (and non-final methods in final classes) to act as if declared with the final keyword.

    This change affects generated bytecode: the ACC_FINAL flag is now only generated if a method is declared with the final modifier.

    fixes #210 fixes #208

    → <<cset 38bf0d5aabc6>>

  2. Log in to comment