Polish contribution

See gh-25367
This commit is contained in:
Sam Brannen
2020-07-16 15:39:36 +02:00
parent 35c0ae7b0c
commit b0570cd3a6
3 changed files with 23 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -712,10 +712,11 @@ public class Indexer extends SpelNodeImpl {
}
TypeDescriptor elementType = this.collectionEntryDescriptor.getElementTypeDescriptor();
try {
Constructor<?> ctor = getConstructor(elementType.getType());
Constructor<?> ctor = getDefaultConstructor(elementType.getType());
int newElements = this.index - this.collection.size();
while (newElements >= 0) {
this.collection.add(ctor == null ? null : ctor.newInstance());
// Insert a null value if the element type does not have a default constructor.
this.collection.add(ctor != null ? ctor.newInstance() : null);
newElements--;
}
}
@@ -725,7 +726,7 @@ public class Indexer extends SpelNodeImpl {
}
}
Constructor<?> getConstructor(Class<?> type) {
private Constructor<?> getDefaultConstructor(Class<?> type) {
try {
return ReflectionUtils.accessibleConstructor(type);
}