Implementing New Contracts

11 views
Skip to first unread message

Dominic Lam Ting Luk

unread,
Dec 8, 2016, 8:02:56 AM12/8/16
to randoop-d...@googlegroups.com
Hi,

My name is Dominic and I'm trying to add a contract to Randoop. The contract I want to add is finding the bug of comparing two objects with == instead of .equals (e.g. Strings). I have looked at the other examples of contracts, but the majority of those deal with multiple objects used in a method such as (o1.compareTo(o2)) or just a single object (isNull). Is it possible to detect two objects not linked by a method? How would I go about detecting when two objects are being compared with the "==" operator? Or is there a better way to detect this bug using Randoop that does not involve contracts?

Thanks,
Dominic

Michael Ernst

unread,
Dec 8, 2016, 8:17:38 AM12/8/16
to Randoop Developers, Dominic Lam Ting Luk
Thanks for your message. I'm glad you are finding Randoop useful.

> finding the bug of comparing two objects with == instead of .equals
> (e.g. Strings)

Randoop will already reveal when comparing two objects with == instead of
.equals leads to inconsistency with .hashCode, or to failures of
transitivity, or to a crash.

More generally, Randoop tells the user when a program behaves incorrectly,
according to a run-time test of a contract. However, Randoop isn't the
right tool to report a static property of the source code, such as the
existence of == comparison.

You could use a static code analysis instead. For example, the Interning
Checker
(https://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#interning-checker)
of the Checker Framework is designed for exactly your use case: it
detects incorrect uses of == where .equals would be needed instead.

-Mike


> Subject: Implementing New Contracts
> From: Dominic Lam Ting Luk <dl...@virginia.edu>
> To: randoop-d...@googlegroups.com
> Date: Thu, 8 Dec 2016 05:18:28 -0500
> --
> You received this message because you are subscribed to the Google
> Groups "Randoop Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to randoop-develop...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages