Skip to content

Commit 7ae3365

Browse files
committed
chore: address Sonar-reported reliability issues
1 parent 51d17b6 commit 7ae3365

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/PathPartIterator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.reflect.Method;
55
import java.lang.reflect.Type;
66
import java.util.Iterator;
7+
import java.util.NoSuchElementException;
78

89
import ai.timefold.solver.core.config.util.ConfigUtils;
910
import ai.timefold.solver.core.preview.api.domain.variable.declarative.ShadowSources;
@@ -28,6 +29,9 @@ public boolean hasNext() {
2829

2930
@Override
3031
public PathPart next() {
32+
if (!hasNext()) {
33+
throw new NoSuchElementException();
34+
}
3135
var index = previous.index() + 1;
3236
var name = parts[index];
3337
var isCollection = false;

python/jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/PythonClassTranslator.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,13 @@ public static InterfaceDeclaration getInterfaceForInstancePythonFunction(String
15931593
pythonParameterTypes[0] = 'L' + instanceInternalClassName + ';';
15941594
}
15951595

1596-
for (int i = 1; i < pythonCompiledFunction.totalArgCount(); i++) {
1596+
return getInterfaceDeclaration(pythonCompiledFunction, parameterPythonTypeList, pythonParameterTypes);
1597+
}
1598+
1599+
private static PythonClassTranslator.InterfaceDeclaration getInterfaceDeclaration(
1600+
PythonCompiledFunction pythonCompiledFunction, List<PythonLikeType> parameterPythonTypeList,
1601+
String[] pythonParameterTypes) {
1602+
for (int i = 1; i < pythonParameterTypes.length; i++) {
15971603
pythonParameterTypes[i] = 'L' + parameterPythonTypeList.get(i).getJavaTypeInternalName() + ';';
15981604
}
15991605
String returnType = 'L' + pythonCompiledFunction.getReturnType().map(PythonLikeType::getJavaTypeInternalName)
@@ -1611,14 +1617,7 @@ public static InterfaceDeclaration getInterfaceForClassPythonFunction(PythonComp
16111617
pythonParameterTypes[0] = Type.getDescriptor(PythonLikeType.class);
16121618
}
16131619

1614-
for (int i = 1; i < pythonCompiledFunction.totalArgCount(); i++) {
1615-
pythonParameterTypes[i] = 'L' + parameterPythonTypeList.get(i).getJavaTypeInternalName() + ';';
1616-
}
1617-
String returnType = 'L' + pythonCompiledFunction.getReturnType().map(PythonLikeType::getJavaTypeInternalName)
1618-
.orElseGet(() -> getPythonReturnTypeOfFunction(pythonCompiledFunction, true).getJavaTypeInternalName()) + ';';
1619-
FunctionSignature functionSignature = new FunctionSignature(returnType, pythonParameterTypes);
1620-
return functionSignatureToInterfaceName.computeIfAbsent(functionSignature,
1621-
PythonClassTranslator::createInterfaceForFunctionSignature);
1620+
return getInterfaceDeclaration(pythonCompiledFunction, parameterPythonTypeList, pythonParameterTypes);
16221621
}
16231622

16241623
public static InterfaceDeclaration createInterfaceForFunctionSignature(FunctionSignature functionSignature) {

0 commit comments

Comments
 (0)