Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-1978

__CLR4_1_2_TEST_NAME_SNIFFER is ambiguous compilation failure

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Highest
    • open-source
    • 3.3.0
    • Instrumentation
    • None
    • Severity 2 - Major

    Description

      Bug affects Clover 3.3.0 and higher.

       

      Steps to reproduce:

      • an inner class must have at least two parents, i.e.
        • extend one class and implement one or more interfaces
        • or implement two or more interfaces
      • Clover instrumentation succeeds
      • Javac compilation fails with an error:

      java: reference to __CLR4_1_2_TEST_NAME_SNIFFER is ambiguous
      {{ both variable __CLR4_1_2_TEST_NAME_SNIFFER in <one class> and variable __CLR4_1_2_TEST_NAME_SNIFFER in <another class> match}}

       

      Code sample:

      class MyBaseTest {
          // the __CLR_4_1_2_TEST_NAME_SNIFFER field is injected here
          void foo() {
          }
      }

       

      interface MyInterface {
          // the __CLR_4_1_2_TEST_NAME_SNIFFER field is injected here
          static void foo() {
          }
      }

       

      class MyTest {
          // the __CLR_4_1_2_TEST_NAME_SNIFFER field is injected here
      
          class InnerTest extends MyBaseTest implements MyInterface {
              // the __CLR_4_1_2_TEST_NAME_SNIFFER field is NOT injected here 
              // because it's an inner class and Clover
              // is designed to re-use field from the outer class
      
              public void test() {
                  // __CLR4_1_2_TEST_NAME_SNIFFER.getTestName() is called
                  // compilation fails because the following three fields are visible in this scope:
                  //   MyBaseTest.__CLR_4_1_2_TEST_NAME_SNIFFER
                  //   MyInterface.__CLR_4_1_2_TEST_NAME_SNIFFER
                  //   MyTest.__CLR_4_1_2_TEST_NAME_SNIFFER
                  // Clover's algorithm expected to use the one from outer MyTest class and 
                  // did not expect to see other fields from super class or interfaces
              }
          }
      }
      

       

      Workaround:

      • as this is related with "multiple inheritance" (as Java interfaces may actually contain business logic - either in a form of static or default methods - Clover adds its code to them), disable instrumentation of interfaces by Clover, e.g. using an inline comment
      ///CLOVER:OFF
      interface MyInterface {
          // no Clover instrumentation will be added
          static void foo() {
          }
      }

       

      Probable fix:

      Try to use fully qualified name (to refer to the outer class or to refer to the parent class), e.g.:

      MyTest.__CLR4_1_2_TEST_NAME_SNIFFER.getTestName()

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            mparfianowicz Marek Parfianowicz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: