From be927785f0249090befb0554f74e513b91b485a4 Mon Sep 17 00:00:00 2001 From: Carlo Alberto Pozzoli Date: Mon, 17 Jun 2024 17:03:18 +0200 Subject: [PATCH] Avoid error when executor assigns an id to a non-identified instance This allows executors called on a non-identified value to provide a new id for the instance, which might be a legit scenario now that we allow to match an executor regardless of the instance being identified or not --- .../evaluation/ExecutingInvocationUnit.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/base/src/main/java/proguard/evaluation/ExecutingInvocationUnit.java b/base/src/main/java/proguard/evaluation/ExecutingInvocationUnit.java index 38b851133..44da3d907 100644 --- a/base/src/main/java/proguard/evaluation/ExecutingInvocationUnit.java +++ b/base/src/main/java/proguard/evaluation/ExecutingInvocationUnit.java @@ -70,7 +70,6 @@ import proguard.evaluation.executor.Executor; import proguard.evaluation.executor.MethodExecutionInfo; import proguard.evaluation.executor.StringReflectionExecutor; -import proguard.evaluation.value.IdentifiedReferenceValue; import proguard.evaluation.value.ReferenceValue; import proguard.evaluation.value.Value; import proguard.evaluation.value.ValueFactory; @@ -294,13 +293,14 @@ private void applySideEffects(MethodResult result) { } private Optional getUpdatedInstance(MethodResult result) { - IdentifiedReferenceValue updatedInstance = - (IdentifiedReferenceValue) result.getUpdatedInstance(); - if (!updatedInstance.isSpecific() || !parameters[0].isSpecific()) { - throw new IllegalStateException( - "An updated instance was provided but either it or the original instance are not specific"); - } - if (!updatedInstance.id.equals(((IdentifiedReferenceValue) parameters[0]).id)) { + ReferenceValue updatedInstance = result.getUpdatedInstance(); + ReferenceValue oldInstance = (ReferenceValue) parameters[0]; + // We log an error if a new instance id is assigned, but it's allowed for the method call to + // assign a new id to a non-identified value + if (updatedInstance.isSpecific() + && oldInstance.isSpecific() + && !PartialEvaluatorUtils.getIdFromSpecificReferenceValue(updatedInstance) + .equals(PartialEvaluatorUtils.getIdFromSpecificReferenceValue(oldInstance))) { log.error( "The updated instance has unexpectedly a different identifier from the calling instance"); return Optional.empty();