#18 new
me (at andresteingress)

call to super method causes precondition violation

Reported by me (at andresteingress) | April 11th, 2011 @ 09:14 PM | in 1.2.6

let's consider this valid piece of precondition overriding:

class Account 
{
    protected BigDecimal balance

    def Account( BigDecimal amount = 0.0 )
    {
        balance = amount
    }

    void deposit( BigDecimal amount )
    {
        balance += amount
    }

    @Requires({ amount >= 0.0 })
    @Ensures({ balance == old.balance - amount })
    BigDecimal withdraw( BigDecimal amount )
    {
        if (balance < amount) return 0.0
        
        balance -= amount
        return amount
    }

    BigDecimal getBalance()
    {
        return balance
    }
}  

class BetterAccount extends Account {
    
    @Requires({ true })
    BigDecimal withdraw( BigDecimal amount )
    {
        return super.withdraw (amount)
    }
}

in the case above, betterAccount.withdraw (null) fails (it shouldn't) because a call to super causes a fresh revalidation

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

core module

Shared Ticket Bins

People watching this ticket

Pages