Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False alarm from ClassInitializationDeadlock for inner enum implementing outer interface with default method #4378

Closed
PhilippWendler opened this issue Apr 29, 2024 · 4 comments

Comments

@PhilippWendler
Copy link

Error Prone 2.27.0 produces a ClassInitializationDeadlock warning for the following code:

public interface TestInterface {

  default Object foo() {
    return null;
  }

  public enum TestEnum implements TestInterface {
    INSTANCE;
  }
}

The exact message is

TestInterface.java:8: warning: [ClassInitializationDeadlock] Possible class initialization deadlock: TestEnum is a subclass of the containing class TestInterface
    INSTANCE;
    ^
    (see https://errorprone.info/bugpattern/ClassInitializationDeadlock)

Interestingly, it does not happen with a class instead of an enum, nor if I remove the default method.

My assumption is that this is a false alarm, because I don't see how initializing TestInterface would require initializing TestEnum.

@cushon
Copy link
Collaborator

cushon commented Apr 29, 2024

Thanks, this is a bug, it should be handling enums as well as classes here, instead of scanning the member enum's fields:

if (member.getKind().equals(Tree.Kind.CLASS)) {
continue;

If there was a field declared directly in TestInterface (instead of nested instead the enum) that could deadlock:

public interface TestInterface {

  default Object foo() {
    return null;
  }

  static final TestInterface FOO = TestEnum.INSTANCE; // possible deadlock

  public enum TestEnum implements TestInterface {
    INSTANCE;
  }
}

It is only reported if the interface has a default method, because interfaces with default methods can participate in class initialization cycles due to the bit about interfaces with 'non-abstract, non-static methods' in JVMS 5.5

@agentgt
Copy link

agentgt commented Apr 29, 2024

Having the same issue. It so far has broken our builds on every project internal and my open source projects.

@cushon assuming this is fixed for the enum implements interface problem will it still report if you have an interface with default methods and/or static final fields even if those fields and/or methods are not used by the enum?

I assume it is just with cycles but given this bug I'm not sure I understand how this check works.

@cushon
Copy link
Collaborator

cushon commented Apr 29, 2024

it will continue to report cases where there's a cyclic dependency between class initializers, including cycles that involve interfaces with default methods and enums.

copybara-service bot pushed a commit that referenced this issue Apr 30, 2024
copybara-service bot pushed a commit that referenced this issue Apr 30, 2024
copybara-service bot pushed a commit that referenced this issue Apr 30, 2024
copybara-service bot pushed a commit that referenced this issue Apr 30, 2024
Stephan202 pushed a commit to PicnicSupermarket/error-prone that referenced this issue Apr 30, 2024
google#4378

PiperOrigin-RevId: 629452163
(cherry picked from commit 6a8f493)
@cushon
Copy link
Collaborator

cushon commented May 1, 2024

I pushed a 2.27.1 release with a fix for this.

@cushon cushon closed this as completed May 1, 2024
ZacSweers pushed a commit to ZacSweers/CatchUp that referenced this issue May 1, 2024
….27.1 (#1418)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[com.google.errorprone:error_prone_annotations](https://errorprone.info)
([source](https://togithub.com/google/error-prone)) | `2.27.0` ->
`2.27.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.errorprone:error_prone_annotations/2.27.0/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.errorprone:error_prone_annotations/2.27.0/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>google/error-prone
(com.google.errorprone:error_prone_annotations)</summary>

###
[`v2.27.1`](https://togithub.com/google/error-prone/releases/tag/v2.27.1):
Error Prone 2.27.1

This release contains all of the changes in
[2.27.0](https://togithub.com/google/error-prone/releases/tag/v2.27.0),
plus a bug fix to
[`ClassInitializationDeadlock`](https://errorprone.info/bugpattern/ClassInitializationDeadlock)
([google/error-prone#4378)

Full Changelog:
google/error-prone@v2.27.0...v2.27.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ZacSweers/CatchUp).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMzEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjMzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit to camunda/zeebe that referenced this issue May 1, 2024
… to v2.27.1 (main) (#18142)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[com.google.errorprone:error_prone_annotations](https://errorprone.info)
([source](https://togithub.com/google/error-prone)) | `2.27.0` ->
`2.27.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.errorprone:error_prone_annotations/2.27.0/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.errorprone:error_prone_annotations/2.27.0/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>google/error-prone
(com.google.errorprone:error_prone_annotations)</summary>

###
[`v2.27.1`](https://togithub.com/google/error-prone/releases/tag/v2.27.1):
Error Prone 2.27.1

[Compare
Source](https://togithub.com/google/error-prone/compare/v2.27.0...v2.27.1)

This release contains all of the changes in
[2.27.0](https://togithub.com/google/error-prone/releases/tag/v2.27.0),
plus a bug fix to
[`ClassInitializationDeadlock`](https://errorprone.info/bugpattern/ClassInitializationDeadlock)
([google/error-prone#4378)

Full Changelog:
google/error-prone@v2.27.0...v2.27.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/camunda/zeebe).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMzEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjMzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJhdXRvbWVyZ2UiXX0=-->
alicejli added a commit to googleapis/sdk-platform-java that referenced this issue May 4, 2024
… to v2.27.1 (#2708)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[com.google.errorprone:error_prone_annotations](https://errorprone.info)
([source](https://togithub.com/google/error-prone)) | `2.26.1` ->
`2.27.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.errorprone:error_prone_annotations/2.26.1/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.errorprone:error_prone_annotations/2.26.1/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>google/error-prone
(com.google.errorprone:error_prone_annotations)</summary>

###
[`v2.27.1`](https://togithub.com/google/error-prone/releases/tag/v2.27.1):
Error Prone 2.27.1

This release contains all of the changes in
[2.27.0](https://togithub.com/google/error-prone/releases/tag/v2.27.0),
plus a bug fix to
[`ClassInitializationDeadlock`](https://errorprone.info/bugpattern/ClassInitializationDeadlock)
([google/error-prone#4378)

Full Changelog:
google/error-prone@v2.27.0...v2.27.1

###
[`v2.27.0`](https://togithub.com/google/error-prone/releases/tag/v2.27.0):
Error Prone 2.27.0

[Compare
Source](https://togithub.com/google/error-prone/compare/v2.26.1...v2.27.0)

New checks:

-
[`ClassInitializationDeadlock`](https://errorprone.info/bugpattern/ClassInitializationDeadlock)
detects class initializers that reference subtypes of the current class,
which can result in deadlocks.
- [`MockitoDoSetup`](https://errorprone.info/bugpattern/MockitoDoSetup)
suggests using `when`/`thenReturn` over `doReturn`/`when` for additional
type safety.
- [`VoidUsed`](https://errorprone.info/bugpattern/VoidUsed) suggests
using a literal `null` instead of referring to a `Void`-typed variable.

Modified checks:

- `TruthSelfEquals` has been renamed and generalized as
[`SelfAssertion`](https://errorprone.info/bugpattern/SelfAssertion)
-
[`RedundantSetterCall`](https://errorprone.info/bugpattern/RedundantSetterCall)
has been improved, and enabled as an error oby default

Closed issues:
[#&#8203;4291](https://togithub.com/google/error-prone/issues/4291).
[#&#8203;4308](https://togithub.com/google/error-prone/issues/4308),
[#&#8203;4343](https://togithub.com/google/error-prone/issues/4343),
[#&#8203;4320](https://togithub.com/google/error-prone/issues/4320)

Full Changelog:
google/error-prone@v2.26.1...v2.27.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/googleapis/sdk-platform-java).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: Alice <65933803+alicejli@users.noreply.github.com>
JoeWang1127 pushed a commit to googleapis/sdk-platform-java that referenced this issue May 14, 2024
… to v2.27.1 (#2709)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[com.google.errorprone:error_prone_annotations](https://errorprone.info)
([source](https://togithub.com/google/error-prone)) | `2.26.1` ->
`2.27.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.errorprone:error_prone_annotations/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.errorprone:error_prone_annotations/2.26.1/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.errorprone:error_prone_annotations/2.26.1/2.27.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>google/error-prone
(com.google.errorprone:error_prone_annotations)</summary>

###
[`v2.27.1`](https://togithub.com/google/error-prone/releases/tag/v2.27.1):
Error Prone 2.27.1

[Compare
Source](https://togithub.com/google/error-prone/compare/v2.27.0...v2.27.1)

This release contains all of the changes in
[2.27.0](https://togithub.com/google/error-prone/releases/tag/v2.27.0),
plus a bug fix to
[`ClassInitializationDeadlock`](https://errorprone.info/bugpattern/ClassInitializationDeadlock)
([google/error-prone#4378)

Full Changelog:
google/error-prone@v2.27.0...v2.27.1

###
[`v2.27.0`](https://togithub.com/google/error-prone/releases/tag/v2.27.0):
Error Prone 2.27.0

[Compare
Source](https://togithub.com/google/error-prone/compare/v2.26.1...v2.27.0)

New checks:

-
[`ClassInitializationDeadlock`](https://errorprone.info/bugpattern/ClassInitializationDeadlock)
detects class initializers that reference subtypes of the current class,
which can result in deadlocks.
- [`MockitoDoSetup`](https://errorprone.info/bugpattern/MockitoDoSetup)
suggests using `when`/`thenReturn` over `doReturn`/`when` for additional
type safety.
- [`VoidUsed`](https://errorprone.info/bugpattern/VoidUsed) suggests
using a literal `null` instead of referring to a `Void`-typed variable.

Modified checks:

- `TruthSelfEquals` has been renamed and generalized as
[`SelfAssertion`](https://errorprone.info/bugpattern/SelfAssertion)
-
[`RedundantSetterCall`](https://errorprone.info/bugpattern/RedundantSetterCall)
has been improved, and enabled as an error oby default

Closed issues:
[#&#8203;4291](https://togithub.com/google/error-prone/issues/4291).
[#&#8203;4308](https://togithub.com/google/error-prone/issues/4308),
[#&#8203;4343](https://togithub.com/google/error-prone/issues/4343),
[#&#8203;4320](https://togithub.com/google/error-prone/issues/4320)

Full Changelog:
google/error-prone@v2.26.1...v2.27.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/googleapis/sdk-platform-java).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjM1MS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants