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

Stricter check for enum classes in EnumModelProvider #558 #559

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

dtim
Copy link
Collaborator

@dtim dtim commented Jul 19, 2022

Co-author: @volivan239

Description

Java enums allow users to declare anonymous classes corresponding to constants. These classes are commonly used to overload toString or methods declared in the enum class. These classes are not enums themselves. According to the comment in the java.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 classes Foo$1 and Foo$2 are (non-direct) subtypes of java.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 is Foo.

These specialized anonymous classes do not have enum constants themselves, and getEnumConstants method will return null 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 on com.google.common.base.CaseFormat class of the Guava library by editing main function body in ContestEstimator.kt:

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

Tests (probably with errors due to other issues) should be generated. Without the fix, a NullPointerException 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: volivan239

Anonymous inner classes declared for enum constants are not enums
themselves, as the necessary condition for being enums is that their
direct supertype is `java.lang.Enum` (see the JavaDoc and comments of
`java.lang.Class#isEnum` method). For these classes, `getEnumConstants`
method returns `null`.
@dtim dtim requested a review from Markoutte July 19, 2022 17:09
@dtim dtim merged commit c85accc into main Jul 20, 2022
@dtim dtim deleted the dtim/558_enum_model_provider_subtype_fix branch July 20, 2022 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

ContestEstimator fails with java.lang.NullPointerException
2 participants