Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stricter check for enum classes in EnumModelProvider #558#559

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dtim merged 1 commit intomainfromdtim/558_enum_model_provider_subtype_fix
Jul 20, 2022

Conversation

@dtim
Copy link
Collaborator

Co-author:@volivan239

Description

Java enums allow users to declare anonymous classes corresponding to constants. These classes are commonly used to overloadtoString or methods declared in the enum class. These classes are not enums themselves. According to the comment in thejava.lang.Class#isEnum method:

        // An enum must both directly extend java.lang.Enum and have        // the ENUM bit set; classes for specialized enum constants        // don't do the former.

Suppose we have an enum:

public enum Foo {    A {        @Override        public String toString() { return "It's A"; }    },    B {        @Override        public String toString() { return "It's B"; }    }}

Anonymous inner classesFoo$1 andFoo$2 are (non-direct) subtypes ofjava.lang.Enum, but are not declared as enums, and are not considered enums from the point of view of the Java specification: their direct superclass isFoo.

These specialized anonymous classes do not have enum constants themselves, andgetEnumConstants method will returnnull for them.

Fixes#558

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (typos and non-functional changes)

How Has This Been Tested?

Automated Testing

No new unit tests are added. All existing tests should pass.

Manual Scenario

Run the contest estimator oncom.google.common.base.CaseFormat class of the Guava library by editingmain function body inContestEstimator.kt:

methodFilter = "com.google.common.base.CaseFormat.*"projectFilter = null

Tests (probably with errors due to other issues) should be generated. Without the fix, aNullPointerException would be thrown, and no tests would be generated.

Checklist:

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All fuzzer tests pass locally with my changes

Co-author: volivan239Anonymous inner classes declared for enum constants are not enumsthemselves, as the necessary condition for being enums is that theirdirect supertype is `java.lang.Enum` (see the JavaDoc and comments of`java.lang.Class#isEnum` method). For these classes, `getEnumConstants`method returns `null`.
@dtimdtim requested a review fromMarkoutteJuly 19, 2022 17:09
@dtimdtim merged commitc85accc intomainJul 20, 2022
@dtimdtim deleted the dtim/558_enum_model_provider_subtype_fix branchJuly 20, 2022 08:12
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@MarkoutteMarkoutteMarkoutte approved these changes

Assignees

No one assigned

Labels

None yet

Projects

Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ContestEstimator fails with java.lang.NullPointerException

3 participants

@dtim@Markoutte

[8]ページ先頭

©2009-2025 Movatter.jp