Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.apache.commons.lang3.Validate.validIndex;

import java.io.IOException;
import java.lang.reflect.Array;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
Expand Down Expand Up @@ -170,7 +171,13 @@ protected CharSequence safeApply(final Object context, final Options options) {
return prefix + StringUtils.join((Iterator) context, (String) separator) + suffix;
}
if (context.getClass().isArray()) {
return prefix + StringUtils.join((Object[]) context, (String) separator) + suffix;
// arrays of primitives (int[], long[], ...) cannot be cast to Object[]
int length = Array.getLength(context);
Object[] items = new Object[length];
for (int i = 0; i < length; i++) {
items[i] = Array.get(context, i);
}
return prefix + StringUtils.join(items, (String) separator) + suffix;
}
// join everything as single values
Object[] values = new Object[options.params.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public void joinArray() throws IOException {
"6, 7, 8");
}

@Test
public void joinPrimitiveArray() throws IOException {
shouldCompileTo(
"{{{join this \", \"}}}", new int[] {6, 7, 8}, $("join", StringHelpers.join), "6, 7, 8");
}

@Test
public void joinValues() throws IOException {
shouldCompileTo(
Expand Down
Loading