INRIA / INRIA/spoon

Inheriting public/static modifier in interface member types

Open
#4,036 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

## Problem statement
```java
interface Foo {
enum Bar {}
}
```
For this Java code `bar.isPublic()`/`bar.isStatic()` returns `false`, as the `Bar` enum does not specify the `public` (or `static`) modifier. However, §9.5 of the JLS specifies (Emphasis mine):
> Every member class or interface declaration in the body of an interface declaration is **implicitly public and static** ( §9.1.1.3). It is permitted to **redundantly** specify either or both of these modifiers

## Tangential problem
Additionally, §8.9 also states
> **A nested enum class is implicitly static.** That is, every member enum class and local enum class is static. It is permitted for the declaration of a member enum class to redundantly specify he static modifier, but it is not permitted for the declaration of a local enum class (§14.3)

So `bar.isStatic()` ought to return true for this reason as well.

## Question
I would expect `isPublic()` to return true there, as the Enum *does* possess the modifier - even if it is not spelled out explicitly. Many tools (like IntelliJ) will automatically remove / warn when specifying `public` for interface members and I wouldn't expect such a change to have semantic impact on Spoon's model.

So, should those types inherit the `public` and `static` modifiers? I do believe that is the expected behavior, but maybe you have a different opinion.

## Impact
My Javadoc Indexer tool throws away quite a few JDK classes (found as `Map.Entry` was missing) as it considers them private. I don't really think it should be my responsibility to walk up the parent chain for every nested type and manually apply the JLS rules for default modifiers.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.