Hello,

While converting Trinidad to Java 5, I found two places where assert is 
used in what I consider a bad way, here's one example of such case:

  public void setCurrentRowSpan(int rowSpan)
  {
    boolean assertEnabled = false;
    assert assertEnabled = true;

    if (rowSpan < 0)
    {
      // preform a reset
      _currRowSpan = 1;
      _currSpanRow = 0;


      if (assertEnabled)
      {
        // make sure prev operation was get:
        assert (_currentRowSpanState == 2);
        _currentRowSpanState = 0; // indicate that we have reset the 
rowspan
      }
    }
    else
    {
      if (rowSpan > _currRowSpan)
        _currRowSpan = rowSpan;

      if (assertEnabled)
      {
        // make sure that the previous operation was a set or reset:
        assert (_currentRowSpanState <= 1);

        // indicate that we have set the rowSpan:
        _currentRowSpanState = 1;
      }
    }
  }


The lines I dislike are assert assertEnabled = true; folowed by the 'if' 
later. This kind of usage, althoguh it emulates #ifdef __DEBUG is not 
really as clean. The goal of assert is to have no performance overhaul 
when disabled. However, with the above example, even when disabled, the 
assert will still add one variable on the stack and evaluate an additional 
'if'. So my suggestion is to completely remove such kind of code (only 2 
places) and forbid it as a coding convention.


Regards,

Simon Lessard
Fujitsu Consulting

Reply via email to