Skip to content

Java: Modifiable.hasModifier(string) reports implicit modifiers #5472

@Marcono1234

Description

@Marcono1234

Description

The documentation for Modifiable.hasModifier(string) says:

For most purposes, the more specialized predicates isAbstract, isPublic, etc. should be used, which also take implicit modifiers into account.

This suggests that it should only hold if an explicit modifier is used. However, this does not seem to be the case.
This makes it difficult to write any queries taking explicit modifier usage into account (e.g. checking for redundant modifiers), and also renders some special casing code in the CodeQL classes pointless.

The current behavior is therefore probably incorrect, only the respective predicates, such as isFinal() or isStatic(), which explicitly mention that they also hold for implicit modifiers should hold. Predicates reporting explicit modifiers such as hasModifier, and probably also getAModifier and hasNoModifier, should not hold. Their documentation should also more clearly mention that they only are supposed to only match explicit modifiers.

Affected cases

(List is likely incomplete)

  • Records: Are always reported as final and, for nested records, static
    Query Console link
  • Enums are always reported as final and, for nested enums, static
  • Nested interfaces are always reported as static
  • Interface methods are always reported as public (unless explicitly private) and abstract (unless default or static)
  • Interface fields are always reported as static

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions