Skip to content

Implement model for String.equals #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/main/java/java/lang/String.java
Original file line number Diff line number Diff line change
Expand Up @@ -1390,11 +1390,33 @@ public byte[] getBytes() {
* @see #equalsIgnoreCase(String)
*
* @diffblue.fullSupport
* @diffblue.untested
*/
public boolean equals(Object anObject) {
// DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
return CProver.nondetBoolean();
// if (this == anObject) {
// return true;
// }
// if (anObject instanceof String) {
// String anotherString = (String)anObject;
// int n = value.length;
// if (n == anotherString.value.length) {
// char v1[] = value;
// char v2[] = anotherString.value;
// int i = 0;
// while (n-- != 0) {
// if (v1[i] != v2[i])
// return false;
// i++;
// }
// return true;
// }
// }
// return false;

// DIFFBLUE MODEL LIBRARY Use CProverString function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ In the other PR, it says "method" instead of "function".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected in the other PR

if (anObject instanceof String) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the models-lib PR, could you add the original code from the JDK, commented out?

return CProverString.equals((String) anObject, this);
}
return false;
}

/**
Expand Down Expand Up @@ -1611,7 +1633,7 @@ public int compareTo(String anotherString) {
// DIFFBLUE MODEL LIBRARY For some reason this needs to be not null for
// FileReader tests to pass.
public static final Comparator<String> CASE_INSENSITIVE_ORDER
= CProver.nondetWithoutNullForNotModelled();
= null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment directly above needs to be updated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this change is necessary or related to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some JBMC tests fail because the type on the left and right correspond (for jbmc). This wasn't a problem before but if we load the model of String.java for using String.equals this also gets loaded.

// DIFFBLUE MODEL LIBRARY Not needed for modelling
// private static class CaseInsensitiveComparator
// implements Comparator<String>, java.io.Serializable {
Expand Down