Skip to content

Enum instantiating with unnecessary reflection #1397

Closed
@alisevych

Description

@alisevych

Description

Some of tests for Enum generated by Symbolic execution are instantiating with unnecessary reflection.

To Reproduce

  1. Run the lrs project in IntelliJ Idea
  2. Install one of the latest plugin builds from main, used 2022.11.546
  3. Use default settings
  4. Use plugin to generate tests for ThreeState enum
  5. Open the generated test

Expected behavior

Enums are supposed to be instantiated without reflection.

Actual behavior

There are several (not all) tests generated by Symbolic execution that use unneeded reflection.

Visual proofs (screenshots, logs, images)

Example:

    ///region OTHER: ERROR SUITE for method mostPositive(java.lang.Iterable)

    @Test
    public void testMostPositive9() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
        ThreeState prevNO = ThreeState.NO;
        try {
            ThreeState no = ThreeState.NO;
            Class threeStateClazz = Class.forName("com.intellij.util.ThreeState");
            setStaticField(threeStateClazz, "NO", no);
            HashSet states = new HashSet();
            ThreeState threeState = ThreeState.YES;
            states.add(threeState);
            states.add(null);
            
            /* This test fails because method [com.intellij.util.ThreeState.mostPositive] produces [java.lang.NullPointerException]
                com.intellij.util.ThreeState.mostPositive(ThreeState.java:40) */
            ThreeState.mostPositive(states);
        } finally {
            setStaticField(ThreeState.class, "NO", prevNO);
        }
    }
    ///endregion

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.3
IntelliJ project, JDK 11

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bugpriority-top-focusTop priority chosen by dev teamspec-customerIssues from customers

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions