Skip to content

Commit

Permalink
code cleanup - reduntant method calls
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Sep 17, 2021
1 parent 1547f59 commit 60008b7
Show file tree
Hide file tree
Showing 96 changed files with 314 additions and 276 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
[//]: # " "
[//]: # " SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause "

[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/eclipse-ee4j/eclipselink.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/eclipse-ee4j/eclipselink/context:java)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/eclipse-ee4j/eclipselink.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/eclipse-ee4j/eclipselink/alerts/)

EclipseLink master (3.1.x)
[![Maven Central](https://img.shields.io/maven-central/v/org.eclipse.persistence/eclipselink.svg?versionPrefix=3.1&label=Maven%20Central)](https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink)
[![Jakarta Staging (Snapshots)](https://img.shields.io/nexus/s/https/jakarta.oss.sonatype.org/org.eclipse.persistence/eclipselink.svg)](https://jakarta.oss.sonatype.org/content/repositories/staging/org/eclipse/persistence/eclipselink)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -90,7 +90,7 @@ public static void setUp() {
}
dynamicHelper = new DynamicHelper(session);
session.login();
new DynamicSchemaManager(session).createTables(new DynamicType[0]);
new DynamicSchemaManager(session).createTables();
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -69,7 +69,7 @@ public static void setUp() {
}
dynamicHelper = new DynamicHelper(session);
session.login();
new DynamicSchemaManager(session).createTables(new DynamicType[0]);
new DynamicSchemaManager(session).createTables();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void test() {
Map statementCache = null;
String sql = getSession().getDescriptor(Address.class).getQueryManager().getInsertQuery().getSQLString();
try {
Method method = uow.getParent().getAccessor().getClass().getDeclaredMethod("getStatementCache", new Class[] { });
Method method = uow.getParent().getAccessor().getClass().getDeclaredMethod("getStatementCache");
method.setAccessible(true);
statementCache = (Map)method.invoke(uow.getParent().getAccessor(), new Object[] { });
statement = (PreparedStatement)statementCache.get(sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void verify() {
// Verify
for (int i = 0; i < nThreads; i++) {
if (tests[i].exception != null) {
throw new org.eclipse.persistence.testing.framework.TestErrorException("exception in thread " + i + ", session(" + String.valueOf(System.identityHashCode(session)) + ") ", tests[i].exception);
throw new org.eclipse.persistence.testing.framework.TestErrorException("exception in thread " + i + ", session(" + System.identityHashCode(session) + ") ", tests[i].exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ protected void setup() throws Throwable {
// executes the method with the same name as the test
@Override
protected void test() throws Exception {
Method method = this.getClass().getDeclaredMethod(getName(), new Class[]{});
method.invoke(this, new Object[] {});
Method method = this.getClass().getDeclaredMethod(getName());
method.invoke(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static TestSuite getCollectionTestSuite() {
suite.addTest(test);

args = new ArrayList();
collection = new ArrayList(Arrays.asList(new String[] { "Ottawa", "Toronto" }));
collection = new ArrayList(Arrays.asList("Ottawa", "Toronto"));
args.add(collection);
args.add("Nepean");
result = new DatabaseRecord();
Expand All @@ -392,7 +392,7 @@ public static TestSuite getCollectionTestSuite() {
suite.addTest(test);

args = new ArrayList();
collection = new ArrayList(Arrays.asList(new Object[] { address, address }));
collection = new ArrayList(Arrays.asList(address, address));
args.add(collection);
args.add("Nepean");
result = new DatabaseRecord();
Expand All @@ -418,7 +418,7 @@ public static TestSuite getCollectionTestSuite() {
suite.addTest(test);

args = new ArrayList();
collection = new ArrayList(Arrays.asList(new Object[] { employee, employee }));
collection = new ArrayList(Arrays.asList(employee, employee));
args.add(collection);
args.add("Nepean");
result = new DatabaseRecord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DescriptorExceptionTest extends AutoVerifyTestCase {

public DescriptorExceptionTest(int errorCode) {
this.errorCode = errorCode;
setName(getName() + " errorCode=" + Integer.toString(errorCode));
setName(getName() + " errorCode=" + errorCode);
}

public DescriptorExceptionTest(int errorCode, String more) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected void initialize() {
protected void invokeTest() throws Throwable {
Method method = this.methodNamed(this.getZName());
try {
method.invoke(this, new Object[0]);
method.invoke(this);
} catch (IllegalAccessException iae) {
throw new RuntimeException("The method '" + method + "' (and its class) must be public.");
} catch (InvocationTargetException ite) {
Expand All @@ -145,7 +145,7 @@ protected void invokeTest() throws Throwable {
*/
private Method methodNamed(String name) {
try {
return this.getClass().getMethod(zName, new Class[0]);
return this.getClass().getMethod(zName);
} catch (NoSuchMethodException ex) {
throw new RuntimeException("Method named " + name + " not found.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Enumeration methodNamesStartingWithTestFor(Class testClass) {
*/
private Constructor singleArgumentConstructorFor(Class testCaseClass) {
try {
return testCaseClass.getConstructor(new Class[] { String.class });
return testCaseClass.getConstructor(String.class);
} catch (NoSuchMethodException e) {
String name = testCaseClass.getName();
throw new RuntimeException("The class '" + name + "' must implement the constructor '" + name + "(String)'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void verify() {
buffer.append(Helper.cr());
for (int i = 0; i < errors.size(); i++) {
Throwable t = (Throwable)errors.get(i);
buffer.append(String.valueOf(t));
buffer.append(t);
buffer.append(Helper.cr());
}
throw new TestErrorException(buffer.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void test() {
@Override
protected void verify() {
if (caughtException != expectedException) {
throw new TestErrorException("The proper exception was not thrown:\n" + "[CAUGHT] " + caughtException + "\n\n[EXPECTING] " + String.valueOf(expectedException));
throw new TestErrorException("The proper exception was not thrown:\n" + "[CAUGHT] " + caughtException + "\n\n[EXPECTING] " + expectedException);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -72,8 +72,8 @@ public void testToValue() {
for (final VersionData data : TO_VALUE_DATA) {
final JavaSEPlatform out = JavaSEPlatform.toValue(data.major, data.minor);
assertEquals("Expected " + data.platform.toString()
+ " for version number " + Integer.toString(data.major) + "."
+ Integer.toString(data.minor), data.platform, out);
+ " for version number " + data.major + "."
+ data.minor, data.platform, out);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public void testStringToPlatform() {
String versionString = JavaSEPlatform.versionString(major, minor);
JavaSEPlatform platform = JavaSEPlatform.toValue(versionString);
assertNotNull("There should exist platform for valid platform"
+" version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]", platform);
+" version number ["+ major +","+ minor +"]", platform);
int[] result = resultMapping(version);
assertTrue("Returned platform version numbers do not match provided"
+ " version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]",
+ " version number ["+ major +","+ minor +"]",
result[0] == platform.getMajor() && result[1] == platform.getMinor());
}
// Invalid version number pairs.
Expand All @@ -129,7 +129,7 @@ public void testStringToPlatform() {
String versionString = JavaSEPlatform.versionString(major, minor);
JavaSEPlatform platform = JavaSEPlatform.toValue(major, minor);
assertTrue("Returned platform shall be JavaSEPlatform.LATEST for invalid version "
+ "number ["+Integer.toString(major)+","+Integer.toString(minor)+"]",
+ "number ["+ major +","+ minor +"]",
LATEST.getMajor() == platform.getMajor() && LATEST.getMinor() == platform.getMinor());
}
}
Expand All @@ -146,10 +146,10 @@ public void testMajorMinorToPlatform() {
int minor = version[1];
JavaSEPlatform platform = JavaSEPlatform.toValue(major, minor);
assertNotNull("There should exist platform for valid platform"
+" version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]", platform);
+" version number ["+ major +","+ minor +"]", platform);
int[] result = resultMapping(version);
assertTrue("Returned platform version numbers do not match provided"
+ " version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]",
+ " version number ["+ major +","+ minor +"]",
result[0] == platform.getMajor() && result[1] == platform.getMinor());
}
// Invalid version number pairs.
Expand All @@ -158,7 +158,7 @@ public void testMajorMinorToPlatform() {
int minor = version[1];
JavaSEPlatform platform = JavaSEPlatform.toValue(major, minor);
assertTrue("Returned platform shall be JavaSEPlatform.LATEST for invalid version "
+ "number ["+Integer.toString(major)+","+Integer.toString(minor)+"]",
+ "number ["+ major +","+ minor +"]",
LATEST.getMajor() == platform.getMajor() && LATEST.getMinor() == platform.getMinor());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public void testPropertyVersionParser() {
final JavaVersion javaVersion = ReflectionHelper.<JavaVersion>invokeStaticMethod(
"propertyVersionParser", JavaVersion.class, new Class[] {String.class}, JavaVersion.class, versionString);
assertNotNull("JavaVersion instance must be returned for valid platform"
+" version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]", javaVersion);
+" version number ["+ major +","+ minor +"]", javaVersion);
assertTrue("Returned JavaVersion instance numbers do not match provided"
+ " version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]", major == javaVersion.getMajor()
+ " version number ["+ major +","+ minor +"]", major == javaVersion.getMajor()
&& minor == javaVersion.getMinor());
} catch (ReflectiveOperationException e) {
fail("Exception: " + e.getMessage());
Expand All @@ -109,9 +109,9 @@ public void testPropertyVersionParser() {
final JavaVersion javaVersion = ReflectionHelper.<JavaVersion>invokeStaticMethod(
"propertyVersionParser", JavaVersion.class, new Class[] {String.class}, JavaVersion.class, versionString);
assertNotNull("JavaVersion instance must be returned for invalid platform"
+" version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]", javaVersion);
+" version number ["+ major +","+ minor +"]", javaVersion);
assertTrue("Returned JavaVersion instance numbers do not match provided"
+ " version number ["+Integer.toString(major)+","+Integer.toString(minor)+"]", major == javaVersion.getMajor()
+ " version number ["+ major +","+ minor +"]", major == javaVersion.getMajor()
&& minor == javaVersion.getMinor());
} catch (ReflectiveOperationException e) {
fail("Exception: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,27 @@ public void compareToForStringArrays() {
newCacheId(new Object[] {"a", "b"}, new Object[] {"b", "c"}),
newCacheId(new Object[] {"a", "b"}, new Object[] {"b", "c"}));
equal("one primaryKey - equal",
newCacheId(new Object[] {"a", "b"}),
newCacheId(new Object[] {"a", "b"}));
newCacheId("a", "b"),
newCacheId("a", "b"));

smaller("one primaryKey - smaller on first element",
newCacheId(new Object[] {"a", "b"}), newCacheId(new Object[] {"b", "c"}));
newCacheId("a", "b"), newCacheId("b", "c"));
greater("one primaryKey - greater on first element",
newCacheId(new Object[] {"b", "c"}), newCacheId(new Object[] {"a", "c"}));
newCacheId("b", "c"), newCacheId("a", "c"));
smaller("one primaryKey - smaller on last element",
newCacheId(new Object[] {"b", "a", "b"}), newCacheId(new Object[] {"b", "a", "c"}));
newCacheId("b", "a", "b"), newCacheId("b", "a", "c"));
greater("one primaryKey - greater on last element",
newCacheId(new Object[] {"0", "0", "c"}), newCacheId(new Object[] {"0", "0", "b"}));
newCacheId("0", "0", "c"), newCacheId("0", "0", "b"));

smaller("many primaryKey - smaller",
newCacheId(new Object[] {"a", "b"}, new Object[] {"b", "b"}), newCacheId(new Object[] {"a", "b"}, new Object[] {"b", "c"}));
greater("many primaryKey - greater",
newCacheId(new Object[] {"b", "c"}, new Object[] {"a", "d"}), newCacheId(new Object[] {"b", "c"}, new Object[] {"a", "c"}));

greater("one primaryKey - smaller by different size",
newCacheId(new Object[] {"a", "b"}), newCacheId(new Object[] {"a"}));
newCacheId("a", "b"), newCacheId("a"));
smaller("one primaryKey - greater by different size",
newCacheId(new Object[] {"b"}), newCacheId(new Object[] {"b", "a"}));
newCacheId("b"), newCacheId("b", "a"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2018 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -77,7 +77,7 @@ private static void verifyBundle(final Class c) {
final Set<String> keys = new HashSet<>();
Object[][] bundle;
try {
Object instance = ReflectionHelper.getInstance(c, new Class[] {}, new Object[] {});
Object instance = ReflectionHelper.getInstance(c, new Class[] {});
bundle = (Object[][])ReflectionHelper.invokeMethod("getContents", instance, new Class[] {}, new Object[] {});
} catch (ReflectiveOperationException | SecurityException e) {
Assert.fail("Could not access " + bundleName + "#getContents()");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -76,14 +76,14 @@ public static void testToValueInt() {
for (LogLevel level : LogLevel.values()) {
int id = level.getId();
LogLevel levelValue = LogLevel.toValue(id);
assertEquals("Log level was not found for ID: " + Integer.toString(id), level, levelValue);
assertEquals("Log level was not found for ID: " + id, level, levelValue);
}
// Check some invalid IDs.
final int[] invalidIds = new int[] { -2, -1, LogLevel.length, LogLevel.length + 1};
for (int id : invalidIds) {
try {
LogLevel.toValue(-1);
fail("LogLevel.toValue(" + Integer.toString(id) + ") shall throw IllegalArgumentException");
fail("LogLevel.toValue(" + id + ") shall throw IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// This exception is expected for illegal IDs.
}
Expand All @@ -99,13 +99,13 @@ public static void testToValueIntFallBack() {
int id = level.getId();
LogLevel levelValue = level == LogLevel.ALL
? LogLevel.toValue(id, LogLevel.OFF) : LogLevel.toValue(id, LogLevel.ALL);
assertEquals("Log level was not found for ID: " + Integer.toString(id), level, levelValue);
assertEquals("Log level was not found for ID: " + id, level, levelValue);
}
// Check some invalid IDs, expecting LogLevel.ALL as fall back.
final int[] invalidIds = new int[] { -2, -1, LogLevel.length, LogLevel.length + 1};
for (int id : invalidIds) {
LogLevel level = LogLevel.toValue(id, LogLevel.ALL);
assertEquals("Expected log level " + LogLevel.ALL.getName() + " for ID: " + Integer.toString(id),
assertEquals("Expected log level " + LogLevel.ALL.getName() + " for ID: " + id,
level, LogLevel.ALL);
}
}
Expand Down
Loading

0 comments on commit 60008b7

Please sign in to comment.