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

investigate coverage of assignment in a boolean expression

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Fix
    • won't fix
    • None
    • None
    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

    Description

      The problem described here http://confluence.atlassian.com/pages/viewpage.action?pageId=79986962 may no longer be as prevalent in jdk 1.4+ .

      Consider instrumenting bool expressions that contain assignments again.
      The following simple, yet very common case of reading from an InputStream compiles with and without clover enabled under jdk 1.4+ :

             String currentLine;
              if ((currentLine = in.readLine()) != null) {
                  System.out.println("currentLine = " + currentLine);
              }
      

      Below is a list of known cases where Clover Instrumentation will cause a compiler error:

      An && expression followed by an assignment

      This generally used to check for null using the short-circuit operator before accessing the variable in the assignment expression.
      Common, real world cases are:

      if (r != null && (n = r.node) != bound && (k = n.key) != null) {
      

      (backport-concurrent-util)
      or

      while((m_inStream != null) && (message = m_inStream.readLine()) != null)
      

      (TestNG)

                  if (lower > 0.0 && (lowerMargin = getLowerMargin()) > 0.0) {
      

      (JFreeChart)

      A constant boolean expression (except true|false)

              final String l;
              if (2 > 0 ) {
                  l = "foo";
              }
              System.out.println("l = " + l);
      

      is instrumented as:

      cov[711]++;if ((((2 > 0 )&&(++cov[712]!=0|true))||(++cov[713]==0&false))) {{
      

      and causes this compiler error:

      [javac] /Users/niick/work/tutorial/build/clover-gen/clover29136.tmp/com/cenqua/samples/money/MoneyTest.java:42: variable l might not have been initialized
          [javac]         }__CLR2_4_2j7j7fpw1ox9g.R.E[715]++;System.out.println("l = " + l);
      
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              npellow Nick
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: