cleanups as suggested by errorprone (#7088)

This commit is contained in:
dahn 2023-10-04 12:04:27 +02:00 committed by GitHub
parent 884953cde1
commit e21b8882e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 12 deletions

View File

@ -22,6 +22,7 @@ This PR...
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] build/CI
### Feature/Enhancement Scale or Bug Severity

View File

@ -149,7 +149,7 @@ public class ConfigKey<T> {
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier,
String displayText, String parent, Ternary<String, String, Long> group, Pair<String, Long> subGroup) {
this(type, name, category, defaultValue, description, isDynamic, scope, multiplier, null, parent, null, null, null, null);
this(type, name, category, defaultValue, description, isDynamic, scope, multiplier, displayText, parent, group, subGroup, null, null);
}
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier,

View File

@ -98,6 +98,8 @@ public class ConfigDepotAdminTest extends TestCase {
ConfigurationVO staticIntCV = new ConfigurationVO("UnitTestComponent", StaticIntCK);
dynamicIntCV.setValue("200");
ConfigurationVO testCV = new ConfigurationVO("UnitTestComponent", TestCK);
ConfigurationGroupVO groupVO = new ConfigurationGroupVO();
ConfigurationSubGroupVO subGroupVO = new ConfigurationSubGroupVO();
when(_configurable.getConfigComponentName()).thenReturn("UnitTestComponent");
when(_configurable.getConfigKeys()).thenReturn(new ConfigKey<?>[] {DynamicIntCK, StaticIntCK, TestCK});
@ -105,6 +107,8 @@ public class ConfigDepotAdminTest extends TestCase {
when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV);
when(_configDao.findById(TestCK.key())).thenReturn(testCV);
when(_configDao.persist(any(ConfigurationVO.class))).thenReturn(dynamicIntCV);
when(_configGroupDao.persist(any(ConfigurationGroupVO.class))).thenReturn(groupVO);
when(_configSubGroupDao.persist(any(ConfigurationSubGroupVO.class))).thenReturn(subGroupVO);
_depotAdmin.populateConfigurations();
// This is once because DynamicIntCK is returned.

View File

@ -86,7 +86,7 @@ public class EntityManagerImpl extends ManagerBase implements EntityManager {
public <T, K> GenericSearchBuilder<T, K> createGenericSearchBuilder(Class<T> entityType, Class<K> resultType) {
GenericDao<T, ? extends Serializable> dao = (GenericDao<T, ? extends Serializable>)GenericDaoBase.getDao(entityType);
return dao.createSearchBuilder((Class<K>)resultType.getClass());
return dao.createSearchBuilder((Class<K>)resultType);
}
@Override

View File

@ -124,7 +124,7 @@ public class DbUtil {
public static Field findField(Class<?> clazz, String columnName) {
for (Field field : clazz.getDeclaredFields()) {
if (field.getAnnotation(Embedded.class) != null || field.getAnnotation(EmbeddedId.class) != null) {
findField(field.getClass(), columnName);
findField(field.getType(), columnName);
} else {
if (columnName.equals(DbUtil.getColumnName(field))) {
return field;
@ -170,7 +170,7 @@ public class DbUtil {
}
if (field.getAnnotation(EmbeddedId.class) != null) {
assert (field.getClass().getAnnotation(Embeddable.class) != null) : "Class " + field.getClass().getName() + " must be Embeddable to be used as Embedded Id";
assert (field.getType().getAnnotation(Embeddable.class) != null) : "Class " + field.getType().getName() + " must be Embeddable to be used as Embedded Id";
return true;
}

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.utils.db;
import java.lang.reflect.InvocationTargetException;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -56,12 +58,13 @@ public class DriverLoader {
}
try {
Class.forName(driverClass).newInstance();
Class<Driver> klazz = (Class<Driver>) Class.forName(driverClass);
klazz.getDeclaredConstructor().newInstance();
LOADED_DRIVERS.add(dbDriver);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Successfully loaded DB driver " + driverClass);
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error("Failed to load DB driver " + driverClass);
throw new CloudRuntimeException("Failed to load DB driver " + driverClass, e);
}

View File

@ -57,10 +57,10 @@ public class EcInfo {
rawClass = HashSet.class;
} else if (List.class == rawClazz) {
rawClass = ArrayList.class;
} else if (Collection.class == Collection.class) {
} else if (Collection.class == rawClazz) {
rawClass = ArrayList.class;
} else {
assert (false) : " We don't know how to create this calss " + rawType.toString() + " for " + attr.field.getName();
assert (false) : " We don't know how to create this class " + rawType.toString() + " for " + attr.field.getName();
}
} catch (NoSuchMethodException e) {
throw new CloudRuntimeException("Write your own support for " + rawClazz + " defined by " + attr.field.getName());

View File

@ -874,7 +874,8 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
if (_idField.getAnnotation(EmbeddedId.class) == null) {
sql.append(_table).append(".").append(DbUtil.getColumnName(_idField, null)).append(" = ? ");
} else {
final Class<?> clazz = _idField.getClass();
s_logger.debug(String.format("field type vs declarator : %s vs %s", _idField.getType(), _idField.getDeclaringClass()));
final Class<?> clazz = _idField.getType();
final AttributeOverride[] overrides = DbUtil.getAttributeOverrides(_idField);
for (final Field field : clazz.getDeclaredFields()) {
sql.append(_table).append(".").append(DbUtil.getColumnName(field, overrides)).append(" = ? AND ");

View File

@ -23,7 +23,7 @@ package com.cloud.utils;
* purposes. This is purely on an honor system though. You should always
**/
public interface SerialVersionUID {
public static final long Base = 0x564D4F70 << 32; // 100 brownie points if you guess what this is and tell me.
public static final long Base = 0x564D4F70L << 32; // 100 brownie points if you guess what this is and tell me.
public static final long UUID = Base | 0x1;
public static final long CloudRuntimeException = Base | 0x2;

View File

@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.log4j.Logger;
@ -160,5 +161,10 @@ public class SubscriptionMgr {
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(this.clazz, this.subscriber, this.methodName, this.method);
}
}
}

View File

@ -716,6 +716,7 @@ public class NetUtilsTest {
NetUtils.isIpv4("2001:db8:300::/64");
}
@Test
public void testAllIpsOfDefaultNic() {
final String defaultHostIp = NetUtils.getDefaultHostIp();
if (defaultHostIp != null) {

View File

@ -87,7 +87,7 @@ public class RedfishClientTest {
public void buildRequestUrlTestHttpsGetSystemId() {
RedfishClient redfishclient = new RedfishClient(USERNAME, PASSWORD, true, false, REDFISHT_REQUEST_RETRIES);
String result = redfishclient.buildRequestUrl(oobAddress, RedfishClient.RedfishCmdType.GetSystemId, systemId);
String expected = String.format("https://%s/redfish/v1/Systems/", oobAddress, systemId);
String expected = String.format("https://%s/redfish/v1/Systems/", oobAddress);
Assert.assertEquals(expected, result);
}
@ -95,7 +95,7 @@ public class RedfishClientTest {
public void buildRequestUrlTestGetSystemId() {
RedfishClient redfishclient = new RedfishClient(USERNAME, PASSWORD, false, false, REDFISHT_REQUEST_RETRIES);
String result = redfishclient.buildRequestUrl(oobAddress, RedfishClient.RedfishCmdType.GetSystemId, systemId);
String expected = String.format("http://%s/redfish/v1/Systems/", oobAddress, systemId);
String expected = String.format("http://%s/redfish/v1/Systems/", oobAddress);
Assert.assertEquals(expected, result);
}