Skip to content

Commit

Permalink
GEODE-6588: Use System.lineSeparator()
Browse files Browse the repository at this point in the history
* Replace synchronized System.getProperty("line.separator") calls with
System.lineSeparator().
  • Loading branch information
jake-at-work committed Nov 16, 2021
1 parent f27c36e commit 9675cf8
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.cache.wan;

import static java.lang.System.lineSeparator;
import static org.apache.geode.cache.Region.SEPARATOR;
import static org.apache.geode.distributed.ConfigurationProperties.DISTRIBUTED_SYSTEM_ID;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
Expand Down Expand Up @@ -223,7 +224,7 @@ private String runListGatewayReceiversCommandInServer(int serverN) {
}

private Vector<String> parseSendersConnectedFromGfshOutput(String gfshOutput) {
String lines[] = gfshOutput.split(System.getProperty("line.separator"));
String lines[] = gfshOutput.split(lineSeparator());
final String sendersConnectedColumnHeader = "Senders Connected";
String receiverInfo = null;
for (int i = 0; i < lines.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.rest.internal.web;

import static java.lang.System.lineSeparator;
import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
Expand Down Expand Up @@ -281,7 +282,7 @@ private String readBody(final ClientHttpResponse response) throws IOException {
String line;

while ((line = responseBodyReader.readLine()) != null) {
buffer.append(line).append(System.getProperty("line.separator"));
buffer.append(line).append(lineSeparator());
}

return buffer.toString().trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.cache.query.dunit;

import static java.lang.System.lineSeparator;
import static org.apache.geode.cache.Region.SEPARATOR;
import static org.apache.geode.distributed.ConfigurationProperties.CACHE_XML_FILE;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
Expand Down Expand Up @@ -722,9 +723,9 @@ public void run2() {
}

// compare.
getLogWriter().info("Execute query : " + System.getProperty("line.separator")
getLogWriter().info("Execute query : " + lineSeparator()
+ " QUERY_STR with index: " + queryStrings[0] + " "
+ System.getProperty("line.separator") + " QUERY_STR without index: "
+ lineSeparator() + " QUERY_STR without index: "
+ queryStrings[1]);
resultsSet.CompareQueryResultsWithoutAndWithIndexes(selectResults, 1, queryStrings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.internal.cache.ha;

import static java.lang.System.lineSeparator;
import static org.apache.geode.cache.Region.SEPARATOR;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
Expand Down Expand Up @@ -530,7 +531,7 @@ public static void validateEventsAtReceivingClientListener(String key) {
if (!containsEventId) {
validationFailed = true;
failureMsg.append("key = ").append(key).append(" ; eventID = ").append(eventIdAtClient2)
.append(System.getProperty("line.separator"));
.append(lineSeparator());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.management.internal.unsafe;

import static java.lang.System.lineSeparator;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -71,7 +72,6 @@ public class ReadOpFileAccessControllerJUnitTest {
private Registry registry = null;

public static final String SERVICE_URLPREFIX = "service:jmx:rmi:///jndi/rmi:";
private static final String NEW_LINE = System.getProperty("line.separator");

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
Expand Down Expand Up @@ -169,9 +169,9 @@ private String createAccessFile() throws IOException {
File file = tempFolder.newFile("jmxremote.access");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.append("admin readwrite");
writer.append(NEW_LINE);
writer.append(lineSeparator());
writer.append("user readonly");
writer.append(NEW_LINE);
writer.append(lineSeparator());
writer.flush();
writer.close();
return file.getAbsolutePath();
Expand All @@ -181,9 +181,9 @@ private String createPasswordFile() throws IOException {
File file = tempFolder.newFile("jmxremote.password");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.append("admin admin");
writer.append(NEW_LINE);
writer.append(lineSeparator());
writer.append("user user");
writer.append(NEW_LINE);
writer.append(lineSeparator());
writer.flush();
writer.close();
return file.getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.admin.internal;

import static java.lang.System.lineSeparator;
import static org.apache.geode.admin.internal.InetAddressUtils.toHostString;
import static org.apache.geode.admin.internal.InetAddressUtilsWithLogging.validateHost;
import static org.apache.geode.distributed.ConfigurationProperties.BIND_ADDRESS;
Expand Down Expand Up @@ -1189,7 +1190,7 @@ public Object clone() throws CloneNotSupportedException {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(1000);
String lf = System.getProperty("line.separator");
String lf = lineSeparator();
if (lf == null) {
lf = ",";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
package org.apache.geode.cache.query.internal.index;

import static java.lang.System.lineSeparator;
import static org.apache.geode.cache.query.internal.CompiledValue.indexThresholdSize;
import static org.apache.geode.internal.lang.SystemUtils.getLineSeparator;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -813,18 +813,18 @@ void recreateIndexData() throws IMQException {
}

public String dump() {
StringBuilder sb = new StringBuilder(toString()).append(" {").append(getLineSeparator());
sb.append(" -----------------------------------------------").append(getLineSeparator());
StringBuilder sb = new StringBuilder(toString()).append(" {").append(lineSeparator());
sb.append(" -----------------------------------------------").append(lineSeparator());
for (Object anEntriesSet : this.entriesSet) {
Entry indexEntry = (Entry) anEntriesSet;
sb.append(" Key = ").append(indexEntry.getKey()).append(getLineSeparator());
sb.append(" Key = ").append(indexEntry.getKey()).append(lineSeparator());
sb.append(" Value Type = ").append(' ').append(indexEntry.getValue().getClass().getName())
.append(getLineSeparator());
.append(lineSeparator());
if (indexEntry.getValue() instanceof Collection) {
sb.append(" Value Size = ").append(' ').append(((Collection) indexEntry.getValue()).size())
.append(getLineSeparator());
.append(lineSeparator());
} else if (indexEntry.getValue() instanceof RegionEntry) {
sb.append(" Value Size = ").append(" " + 1).append(getLineSeparator());
sb.append(" Value Size = ").append(" " + 1).append(lineSeparator());
} else {
throw new AssertionError("value instance of " + indexEntry.getValue().getClass().getName());
}
Expand All @@ -837,9 +837,9 @@ public String dump() {
if (value instanceof Collection) {
sb.append(" Value.size = ").append(((Collection) value).size());
}
sb.append(getLineSeparator());
sb.append(lineSeparator());
}
sb.append(" -----------------------------------------------").append(getLineSeparator());
sb.append(" -----------------------------------------------").append(lineSeparator());
}
sb.append("}// Index ").append(getName()).append(" end");
return sb.toString();
Expand Down Expand Up @@ -983,11 +983,11 @@ public void close() {

public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("No Keys = ").append(getNumberOfKeys()).append(getLineSeparator());
sb.append("No Values = ").append(getNumberOfValues()).append(getLineSeparator());
sb.append("No Uses = ").append(getTotalUses()).append(getLineSeparator());
sb.append("No Updates = ").append(getNumUpdates()).append(getLineSeparator());
sb.append("Total Update time = ").append(getTotalUpdateTime()).append(getLineSeparator());
sb.append("No Keys = ").append(getNumberOfKeys()).append(lineSeparator());
sb.append("No Values = ").append(getNumberOfValues()).append(lineSeparator());
sb.append("No Uses = ").append(getTotalUses()).append(lineSeparator());
sb.append("No Updates = ").append(getNumUpdates()).append(lineSeparator());
sb.append("Total Update time = ").append(getTotalUpdateTime()).append(lineSeparator());
return sb.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.apache.geode.cache.query.internal.index;

import static org.apache.geode.internal.lang.SystemUtils.getLineSeparator;
import static java.lang.System.lineSeparator;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public String toString() {
if (ind instanceof FutureTask) {
continue;
}
sb.append(ind).append(getLineSeparator());
sb.append(ind).append(lineSeparator());
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.apache.geode.internal.cache;

import static java.lang.System.lineSeparator;

import java.io.PrintStream;
import java.util.EnumSet;
import java.util.Map;
Expand Down Expand Up @@ -914,7 +916,7 @@ public void dump(PrintStream printStream) {
}

public String dump2() {
final String lineSeparator = System.getProperty("line.separator");
final String lineSeparator = lineSeparator();
StringBuffer sb = new StringBuffer();
String name = getName();
if (isBucket() && logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY_VERBOSE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.apache.geode.internal.cache;

import static java.lang.System.lineSeparator;

import java.io.BufferedInputStream;
import java.io.DataInput;
import java.io.DataOutput;
Expand Down Expand Up @@ -2555,7 +2557,7 @@ private String basicModifyRegion(boolean printInfo, DiskRegionView drv, String l
boolean statisticsEnabled = drv.getStatisticsEnabled();
boolean offHeap = drv.getOffHeap();
StringBuilder sb = new StringBuilder();
final String lineSeparator = System.getProperty("line.separator");
final String lineSeparator = lineSeparator();

if (lruOption != null) {
EvictionAlgorithm ea = EvictionAlgorithm.parseAction(lruOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/
package org.apache.geode.internal.cache;

import static java.lang.System.lineSeparator;
import static org.apache.geode.internal.cache.LocalRegion.InitializationLevel.AFTER_INITIAL_IMAGE;
import static org.apache.geode.internal.cache.LocalRegion.InitializationLevel.ANY_INIT;
import static org.apache.geode.internal.cache.LocalRegion.InitializationLevel.BEFORE_INITIAL_IMAGE;
import static org.apache.geode.internal.lang.SystemUtils.getLineSeparator;
import static org.apache.geode.internal.offheap.annotations.OffHeapIdentifier.ENTRY_EVENT_NEW_VALUE;
import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;

Expand Down Expand Up @@ -4354,17 +4354,17 @@ private void logKeys(List serverKeys, InterestResultPolicy pol) {
if (key instanceof VersionedObjectList) {
Set keys = ((VersionedObjectList) key).keySet();
for (Object k : keys) {
buffer.append(" ").append(k).append(getLineSeparator());
buffer.append(" ").append(k).append(lineSeparator());
}
} else {
buffer.append(" ").append(key).append(getLineSeparator());
buffer.append(" ").append(key).append(lineSeparator());
}
}
}
} // for
if (logger.isDebugEnabled()) {
logger.debug("{} refreshEntriesFromServerKeys count={} policy={}{}{}", this, totalKeys, pol,
getLineSeparator(), buffer);
lineSeparator(), buffer);
}
}

Expand Down Expand Up @@ -8465,8 +8465,8 @@ void clearRegionLocally(RegionEventImpl regionEvent, boolean cacheWrite,
if (rvv != null && getDataPolicy().withStorage()) {
if (isRvvDebugEnabled) {
logger.trace(LogMarker.RVV_VERBOSE,
"waiting for my version vector to dominate{}mine={}{} other={}", getLineSeparator(),
getLineSeparator(), versionVector.fullToString(), rvv);
"waiting for my version vector to dominate{}mine={}{} other={}", lineSeparator(),
lineSeparator(), versionVector.fullToString(), rvv);
}
boolean result = versionVector.waitToDominate(rvv, this);
if (!result) {
Expand Down Expand Up @@ -8988,7 +8988,7 @@ VersionedObjectList basicPutAll(final Map<?, ?> map,
if (isDebugEnabled) {
logger.debug(
"putAll in client encountered a PutAllPartialResultException:{}{}. Adjusted keys are: {}",
e.getMessage(), getLineSeparator(), proxyResult.getKeys());
e.getMessage(), lineSeparator(), proxyResult.getKeys());
}
Throwable txException = e.getFailure();
while (txException != null) {
Expand Down Expand Up @@ -9205,7 +9205,7 @@ public VersionedObjectList basicRemoveAll(final Collection<Object> keys,
if (isDebugEnabled) {
logger.debug(
"removeAll in client encountered a BulkOpPartialResultException: {}{}. Adjusted keys are: {}",
e.getMessage(), getLineSeparator(), proxyResult.getKeys());
e.getMessage(), lineSeparator(), proxyResult.getKeys());
}
Throwable txException = e.getFailure();
while (txException != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
package org.apache.geode.internal.cache;

import static java.lang.System.lineSeparator;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toSet;
import static org.apache.geode.internal.lang.SystemUtils.getLineSeparator;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -717,13 +717,13 @@ public void clear() {

public synchronized String dump() {
StringBuilder sb = new StringBuilder("prIdToPR Map@");
sb.append(System.identityHashCode(prIdToPR)).append(':').append(getLineSeparator());
sb.append(System.identityHashCode(prIdToPR)).append(':').append(lineSeparator());
Map.Entry mapEntry;
for (Iterator iterator = prIdToPR.entrySet().iterator(); iterator.hasNext();) {
mapEntry = (Map.Entry) iterator.next();
sb.append(mapEntry.getKey()).append("=>").append(mapEntry.getValue());
if (iterator.hasNext()) {
sb.append(getLineSeparator());
sb.append(lineSeparator());
}
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package org.apache.geode.internal.lang;

import static java.lang.System.lineSeparator;

import java.util.Arrays;
import java.util.stream.Collectors;

Expand All @@ -33,9 +35,9 @@
@Deprecated
public class StringUtils extends org.apache.commons.lang3.StringUtils {

public static final String COMMA_DELIMITER = ",";
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
public static final String SPACE = " ";
static final String COMMA_DELIMITER = ",";
static final String LINE_SEPARATOR = lineSeparator();
static final String SPACE = " ";

private static final int MAX_ARRAY_ELEMENTS_TO_CONVERT =
Integer.getInteger("StringUtils.MAX_ARRAY_ELEMENTS_TO_CONVERT", 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.internal.lang;


import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -48,8 +49,6 @@ public class SystemUtils {
public static final String WINDOWS_OS_NAME = "Windows";
public static final String SOLARIS_OS_NAME = "SunOS";

private static final String LINE_SEPARATOR = System.getProperty("line.separator");

/**
* Utility method to determine whether the Java application process is executing on the Apple JVM.
*
Expand Down Expand Up @@ -255,11 +254,4 @@ private static boolean isOS(final String expectedOsName) {
return osName != null && osName.contains(expectedOsName);
}

/**
* Returns the value of {@code System.getProperty("line.separator")}.
*/
public static String getLineSeparator() {
return LINE_SEPARATOR;
}

}
Loading

0 comments on commit 9675cf8

Please sign in to comment.