Skip to content

Commit 5492a60

Browse files
committed
fixed call to safe copy
1 parent 25e14db commit 5492a60

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/service/HarvestActualHttpWsResponseHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class HarvestActualHttpWsResponseHandler {
535535
val v = ParamUtil.getValueGene(geneToMutate)
536536
val t = ParamUtil.getValueGene(template)
537537
if (v::class.java == t::class.java) {
538-
v.unsafeCopyValueFrom(t)
538+
v.copyValueFrom(t)
539539
return true
540540
} else if (v is StringGene) {
541541
// add template as part of specialization

core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class RestCallAction(
191191
For example, they could be a ChoiceGene when dealing with "examples" or Regex when having patterns
192192
only defined on some endpoints
193193
*/
194-
parameters[i].primaryGene().unsafeCopyValueFrom(k.primaryGene())
194+
parameters[i].primaryGene().copyValueFrom(k.primaryGene())
195195
}
196196
}
197197
}

core/src/main/kotlin/org/evomaster/core/search/gene/Gene.kt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,19 +1140,10 @@ abstract class Gene(
11401140
*
11411141
* @return if the update was successful
11421142
*/
1143-
fun copyValueFrom(gene: Gene, undoIfUpdateFails: Boolean = true): Boolean {
1144-
1145-
//FIXME current implementation leads to infinite loops. must fix copyValueFrom
1146-
//return updateValueOnlyIfValid( { unsafeCopyValueFrom(gene) } , undoIfUpdateFails)
1147-
//TODO update once fixed
1148-
return unsafeCopyValueFrom(gene)
1143+
fun copyValueFrom(gene: Gene): Boolean {
1144+
return updateValueOnlyIfValid( { unsafeCopyValueFrom(gene) }, true)
11491145
}
11501146

1151-
/*
1152-
FIXME: looks like redundancies and inconsistencies between copyValueFrom and setFromDifferentGene.
1153-
TODO once fixed, update
1154-
*/
1155-
11561147
/**
11571148
* Given a string value, apply it to the current state of this gene (and possibly recursively to its children).
11581149
* If it fails for any reason, return false.
@@ -1184,25 +1175,28 @@ abstract class Gene(
11841175

11851176

11861177
/**
1187-
* here `valid` means that 1) [updateValue] performs correctly, ie, returns true AND 2) isLocallyValid is true
1178+
* here `valid` means that 1) [updateValue] performs correctly, ie, returns true AND 2) [isGloballyValid] is true
11881179
*
11891180
* @param updateValue lambda performs update of value of the gene
1190-
* @param undoIfUpdateFails represents whether it needs to undo the value update if [undoIfUpdateFails] returns false
1181+
* @param undoIfUpdateFails represents whether it needs to undo the value update if [updateValue] returns false
11911182
*
11921183
* @return if the value is updated with [updateValue]
11931184
*/
11941185
fun updateValueOnlyIfValid(updateValue: () -> Boolean, undoIfUpdateFails: Boolean): Boolean {
1186+
1187+
if(!undoIfUpdateFails) {
1188+
return updateValue()
1189+
}
1190+
11951191
val current = copy()
11961192
val ok = updateValue()
1197-
if (!ok && !undoIfUpdateFails) return false
11981193

1199-
if (!ok || !isLocallyValid()) {
1194+
if (!ok || !isGloballyValid()) {
12001195
val success = unsafeCopyValueFrom(current)
12011196
assert(success)
12021197
return false
12031198
}
12041199
return true
1205-
12061200
}
12071201

12081202
/**

0 commit comments

Comments
 (0)