diff --git a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/PathPartIterator.java b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/PathPartIterator.java index af2f1b828c4..f4e6981aa77 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/PathPartIterator.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/PathPartIterator.java @@ -4,6 +4,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Iterator; +import java.util.NoSuchElementException; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.preview.api.domain.variable.declarative.ShadowSources; @@ -28,6 +29,9 @@ public boolean hasNext() { @Override public PathPart next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } var index = previous.index() + 1; var name = parts[index]; var isCollection = false; diff --git a/python/jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/PythonClassTranslator.java b/python/jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/PythonClassTranslator.java index 573ef946d8d..79d598de2d9 100644 --- a/python/jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/PythonClassTranslator.java +++ b/python/jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/PythonClassTranslator.java @@ -1593,7 +1593,13 @@ public static InterfaceDeclaration getInterfaceForInstancePythonFunction(String pythonParameterTypes[0] = 'L' + instanceInternalClassName + ';'; } - for (int i = 1; i < pythonCompiledFunction.totalArgCount(); i++) { + return getInterfaceDeclaration(pythonCompiledFunction, parameterPythonTypeList, pythonParameterTypes); + } + + private static PythonClassTranslator.InterfaceDeclaration getInterfaceDeclaration( + PythonCompiledFunction pythonCompiledFunction, List parameterPythonTypeList, + String[] pythonParameterTypes) { + for (int i = 1; i < pythonParameterTypes.length; i++) { pythonParameterTypes[i] = 'L' + parameterPythonTypeList.get(i).getJavaTypeInternalName() + ';'; } String returnType = 'L' + pythonCompiledFunction.getReturnType().map(PythonLikeType::getJavaTypeInternalName) @@ -1611,14 +1617,7 @@ public static InterfaceDeclaration getInterfaceForClassPythonFunction(PythonComp pythonParameterTypes[0] = Type.getDescriptor(PythonLikeType.class); } - for (int i = 1; i < pythonCompiledFunction.totalArgCount(); i++) { - pythonParameterTypes[i] = 'L' + parameterPythonTypeList.get(i).getJavaTypeInternalName() + ';'; - } - String returnType = 'L' + pythonCompiledFunction.getReturnType().map(PythonLikeType::getJavaTypeInternalName) - .orElseGet(() -> getPythonReturnTypeOfFunction(pythonCompiledFunction, true).getJavaTypeInternalName()) + ';'; - FunctionSignature functionSignature = new FunctionSignature(returnType, pythonParameterTypes); - return functionSignatureToInterfaceName.computeIfAbsent(functionSignature, - PythonClassTranslator::createInterfaceForFunctionSignature); + return getInterfaceDeclaration(pythonCompiledFunction, parameterPythonTypeList, pythonParameterTypes); } public static InterfaceDeclaration createInterfaceForFunctionSignature(FunctionSignature functionSignature) {