nfsantos commented on code in PR #1353: URL: https://github.com/apache/jackrabbit-oak/pull/1353#discussion_r1521130109
########## oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java: ########## @@ -336,6 +339,37 @@ private boolean indexProperty(String path, return dirty; } + static String getValueAsTruncatedString(Object val) { + String value = val.toString(); + boolean isArray = value.startsWith("[") && value.endsWith("]"); + return value.length() <= LOG_TRUNCATION_LENGTH ? value + : value.substring(0, LOG_TRUNCATION_LENGTH) + "..." + (isArray ? "]" : ""); + } + + static String truncateForLogging(PropertyState property) { + Type<?> t = property.getType(); + if (t.isArray()) { + if (property.count() == 0) { + return "[]"; + } + + Type<?> base = t.getBaseType(); + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (int i = 0; i < property.count(); i++) { + sb.append(property.getValue(base, i)); + if (i < property.count() - 1) { + sb.append(", "); + } + } + sb.append("]"); Review Comment: This would be cleaner in functional style, something like: ``` IntStream.range(0, property.count()) .mapToObj(i -> property.getValue(Type.STRING, i)) .collect(Collectors.joining(",", "[", "]")); ``` Maybe less efficient, but this is code is not in a hotspot, so it does not matter. ########## oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java: ########## @@ -336,6 +339,37 @@ private boolean indexProperty(String path, return dirty; } + static String getValueAsTruncatedString(Object val) { + String value = val.toString(); Review Comment: Maybe trim the string before testing below for starting and ending with [ ]. ########## oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java: ########## @@ -336,6 +339,37 @@ private boolean indexProperty(String path, return dirty; } + static String getValueAsTruncatedString(Object val) { + String value = val.toString(); + boolean isArray = value.startsWith("[") && value.endsWith("]"); + return value.length() <= LOG_TRUNCATION_LENGTH ? value Review Comment: Personal opinion: in this situation, I find the ternary operator harder to read than an if-then-else. It was also the reason why I misunderstood the code initially, and thought that there was a risk of out of bounds exception. But it's a matter of personal preference, so feel free to leave it as it is. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org