#206 Check assertions have no side effects

open
nobody
Check (274)
2
2012-10-10
2003-06-08
Tim Tyler
No

Assertions with side effects are a source of problems.

They can cause the deployed program to behave
differently from the developed one.

An exhaustive check for assert statements not having
side effects might be difficult to implement - since it
involves exploring any called methods - however there
seems to be the possibility of a conservative check - e.g.
reject anything containing an assignment or method
call.

Discussion

  • Logged In: YES
    user_id=746148

    I think that simple check could be done using
    DescendantToken check:
    <module name="DescendantToken">
    <property name="tokens" value="LITERAL_ASSERT"/>
    <property name="limitedTokens"
    value="ASSIGN,DEC,INC,POST_DEC,

    POST_INC,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,DIV_ASSIGN,MOD_ASSIGN,

    BSR_ASSIGN,SR_ASSIGN,SL_ASSIGN,BAND_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN,
    METHOD_CALL"/>
    <property name="maximumNumber" value="0"/>
    </module>

     
  • Logged In: YES
    user_id=746148

    I lower priority since simple check can be done using
    DescendantToken
    check. And it looks that implementation of full check migth
    be very
    dificult (if possible).