Skip to content

Commit

Permalink
RANGER-5017: updated sources to address 'may produce NullPointerExcep…
Browse files Browse the repository at this point in the history
…tion' warning, and use <> operator while instantiating generic types (#515)
  • Loading branch information
mneethiraj authored Jan 22, 2025
1 parent 0a09509 commit 8f9bedf
Show file tree
Hide file tree
Showing 35 changed files with 136 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ void appendToDoneFile(AuditIndexRecord indexRecord) throws IOException {
try {
AuditIndexRecord record = MiscUtil.fromJson(line, AuditIndexRecord.class);

if (record == null) {
continue;
}

logFile = new File(record.getFilePath());
archiveFile = new File(archiveFolder, logFile.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,10 @@ void appendToDoneFile(AuditIndexRecord indexRecord) throws IOException {
try {
AuditIndexRecord record = MiscUtil.fromJson(line, AuditIndexRecord.class);

if (record == null) {
continue;
}

logFile = new File(record.getFilePath());
archiveFile = new File(archiveFolder, logFile.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BinarySearchTree() {
}

public void insert(final T value) {
Node<T> node = new Node<T>(value);
Node<T> node = new Node<>(value);

if (root == null) {
root = node;
Expand Down Expand Up @@ -104,7 +104,7 @@ void setRoot(final Node<T> newRoot) {
}

void rebalance() {
Node<T> dummy = new Node<T>(null);
Node<T> dummy = new Node<>(null);

dummy.setRight(root);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public BinarySearchTree<RangerGeolocationData, Long> getData() {
}

public void setData(final BinarySearchTree<RangerGeolocationData, Long> dataArg) {
data = dataArg != null ? dataArg : new BinarySearchTree<RangerGeolocationData, Long>();
data = dataArg != null ? dataArg : new BinarySearchTree<>();
}

public void dump(ValuePrinter<RangerGeolocationData> processor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2543,22 +2543,20 @@ public int hashCode() {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
} else if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
} else if (getClass() != obj.getClass()) {
return false;
}

RangerPolicyConditionDef other = (RangerPolicyConditionDef) obj;
if (itemId == null) {
if (other.itemId != null) {
return false;
}
} else if (other.itemId != null || !itemId.equals(other.itemId)) {
} else if (!itemId.equals(other.itemId)) {
return false;
}

if (description == null) {
if (other.description != null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.Set;

public class GdsProjectEvaluator {
private static final Logger LOG = LoggerFactory.getLogger(GdsDatasetEvaluator.class);
private static final Logger LOG = LoggerFactory.getLogger(GdsProjectEvaluator.class);

public static final GdsProjectEvalOrderComparator EVAL_ORDER_COMPARATOR = new GdsProjectEvalOrderComparator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private Map<String, RangerPolicyResource> createDefaultDBPolicyResource() {
}

private List<RangerPolicyItem> createDefaultDBPolicyItem() {
List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
List<RangerPolicyItemAccess> accesses = new ArrayList<>();

accesses.add(new RangerPolicyItemAccess(ACCESS_TYPE_CREATE));

Expand Down Expand Up @@ -241,7 +241,7 @@ private Map<String, RangerPolicyResource> createInformationSchemaPolicyResource(
}

private List<RangerPolicyItem> createInformationSchemaPolicyItem() {
List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
List<RangerPolicyItemAccess> accesses = new ArrayList<>();

accesses.add(new RangerPolicyItemAccess(ACCESS_TYPE_SELECT));
RangerPolicyItem item = new RangerPolicyItem(accesses, null, Collections.singletonList(RangerPolicyEngine.GROUP_PUBLIC), null, null, false);
Expand Down
4 changes: 2 additions & 2 deletions intg/src/main/java/org/apache/ranger/RangerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private void authInit(String authType, String username, String password) {
isSecureMode = true;
MiscUtil.loginWithKeyTab(password, username, null);
UserGroupInformation ugi = MiscUtil.getUGILoginUser();
LOG.info("RangerClient.authInit() UGI user: " + ugi.getUserName() + " principal: " + username);
LOG.info("RangerClient.authInit() UGI user: {} principal: {}", ugi.getUserName(), username);
} else {
restClient.setBasicAuthInfo(username, password);
}
Expand All @@ -510,7 +510,7 @@ private ClientResponse invokeREST(API api, Map<String, String> params, Object re
break;

default:
LOG.error(api.getMethod() + ": unsupported HTTP method");
LOG.error("{}: unsupported HTTP method", api.getMethod());

clientResponse = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void updateDBSSLURL() {

jpaProperties.put(JPA_DB_URL, conf.get(PROPERTY_PREFIX + DB_URL));

logger.info(PROPERTY_PREFIX + DB_URL + "=" + conf.get(PROPERTY_PREFIX + DB_URL));
logger.info("{}{}={}", PROPERTY_PREFIX, DB_URL, conf.get(PROPERTY_PREFIX + DB_URL));

if ("true".equalsIgnoreCase(dbSslVerifyServerCertificate) || "true".equalsIgnoreCase(dbSslRequired)) {
if (!"1-way".equalsIgnoreCase((dbSslAuthType))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void engineLoad(InputStream stream, char[] password) throws IOException,
int counter = 0;

for (int i = computed.length - 1; i >= 0; i--) {
if (computed[i] != data[data.length - (1 + counter)]) {
if (data == null || computed[i] != data[data.length - (1 + counter)]) {
Throwable t = new UnrecoverableKeyException("Password verification failed");

logger.error("Keystore was tampered with, or password was incorrect.", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void getKMSMetricCalculation(String caseValue) {
String jsonEncKeyByAlgo = null;

if (keyProvider != null && keyProvider.getKeys() != null && keyProvider.getKeys().size() > 0) {
List<String> keyList = new ArrayList<String>();
List<String> keyList = new ArrayList<>();

keyList.addAll(keyProvider.getKeys());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class RangerMetricsSystemWrapper {
public void init(String serviceName, List<RangerMetricsSourceWrapper> sourceWrappers, List<RangerMetricsSinkWrapper> sinkWrappers) {
// Initialize metrics system
MetricsSystem metricsSystem = DefaultMetricsSystem.initialize(serviceName);
Set<String> sourceContexts = new HashSet<String>();
Set<String> sourceContexts = new HashSet<>();
sourceContexts.add(serviceName);

// Ranger Source
if (Objects.isNull(sourceWrappers) || sourceWrappers.isEmpty()) {
sourceWrappers = new ArrayList<RangerMetricsSourceWrapper>();
sourceWrappers = new ArrayList<>();
}
sourceWrappers.add(new RangerMetricsSourceWrapper("RangerJVM", "Ranger common metric source (RangerMetricsJvmSource)", serviceName, new RangerMetricsJvmSource(serviceName)));
sourceWrappers.add(new RangerMetricsSourceWrapper("RangerContainer", "Ranger web container metric source (RangerMetricsContainerSource)", serviceName, new RangerMetricsContainerSource(serviceName)));
Expand All @@ -72,7 +72,7 @@ public void init(String serviceName, List<RangerMetricsSourceWrapper> sourceWrap

// Ranger Sink
if (Objects.isNull(sinkWrappers) || sinkWrappers.isEmpty()) {
sinkWrappers = new ArrayList<RangerMetricsSinkWrapper>();
sinkWrappers = new ArrayList<>();
}

// Prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,16 @@ public FilterLogEventsRequest getFilterLogEventsRequest(AWSLogs client, SearchCr
// Add FilterPattern which will only fetch logs required
FilterLogEventsRequest filterLogEventsRequest = new FilterLogEventsRequest()
.withLogGroupName(logGroupName)
.withStartTime(fromDate.getTime())
.withEndTime(toDate.getTime())
.withFilterPattern(filterPattern.toString());

if (fromDate != null) {
filterLogEventsRequest.withStartTime(fromDate.getTime());
}

if (toDate != null) {
filterLogEventsRequest.withEndTime(toDate.getTime());
}

if (StringUtils.isNotBlank(logStreamPrefix)) {
filterLogEventsRequest.setLogStreamNamePrefix(logStreamPrefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public class RoleUserAuthorityGranter implements AuthorityGranter {
@Override
public Set<String> grant(Principal principal) {
if (principal instanceof UnixGroupPrincipal) {
Collections.singleton(principal.getName());
return Collections.singleton(principal.getName());
} else {
Collections.singleton("ROLE_USER");
return Collections.singleton("ROLE_USER");
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ public List<String> lookupResource(String serviceName, ResourceLookupContext con
}
}

Map<String, String> newConfigs = rangerSvcService.getConfigsWithDecryptedPassword(service);
RangerBaseService svc = null;

service.setConfigs(newConfigs);
if (service != null) {
Map<String, String> newConfigs = rangerSvcService.getConfigsWithDecryptedPassword(service);

RangerBaseService svc = getRangerServiceByService(service, svcStore);
service.setConfigs(newConfigs);

svc = getRangerServiceByService(service, svcStore);
}

LOG.debug("==> ServiceMgr.lookupResource for Service: ({}Context: {})", svc, context);

Expand Down Expand Up @@ -663,7 +667,7 @@ public T call() throws Exception {
} finally {
Thread.currentThread().setContextClassLoader(clsLoader);

if (LOG.isDebugEnabled()) {
if (start != null) {
Date finish = new Date();
long waitTime = start.getTime() - creation.getTime();
long executionTime = finish.getTime() - start.getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public Boolean parseBoolean(String value, String errorMessage, MessageEnums mess
}

public WebApplicationException createRESTException(String errorMessage, MessageEnums messageEnum, Long objectId, String fieldName, String logMessage, int statusCode) {
List<VXMessage> messageList = new ArrayList<VXMessage>();
List<VXMessage> messageList = new ArrayList<>();

messageList.add(messageEnum.getMessage(objectId, fieldName));

Expand Down Expand Up @@ -407,7 +407,7 @@ public WebApplicationException createRESTException(String errorMessage, MessageE
}

public WebApplicationException create404RESTException(String errorMessage, MessageEnums messageEnum, Long objectId, String fieldName, String logMessage) {
List<VXMessage> messageList = new ArrayList<VXMessage>();
List<VXMessage> messageList = new ArrayList<>();

messageList.add(messageEnum.getMessage(objectId, fieldName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RangerProperties extends HashMap<Object, Object> {

private static final String XMLCONFIG_FILENAME_DELIMITOR = ",";

private String xmlConfigFileNames;
private final String xmlConfigFileNames;

public RangerProperties(String xmlConfigFileNames) {
this.xmlConfigFileNames = xmlConfigFileNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,10 @@ protected void resolveQueryParams(Query query, SearchFilter searchCriteria, List
} else if (searchField.getDataType() == SearchField.DATA_TYPE.STR_LIST || (isMultiValue && searchField.getDataType() == SearchField.DATA_TYPE.STRING)) {
List<String> strValueList = new ArrayList<>();

for (Object value : multiValue) {
strValueList.add(String.valueOf(value));
if (multiValue != null) {
for (Object value : multiValue) {
strValueList.add(String.valueOf(value));
}
}

if (!strValueList.isEmpty()) {
Expand Down Expand Up @@ -593,8 +595,10 @@ private StringBuilder buildWhereClause(SearchFilter searchCriteria, List<SearchF
} else if (searchField.getDataType() == SearchField.DATA_TYPE.STR_LIST || (isMultiValue && searchField.getDataType() == SearchField.DATA_TYPE.STRING)) {
List<String> strValueList = new ArrayList<>();

for (Object value : multiValue) {
strValueList.add(String.valueOf(value));
if (multiValue != null) {
for (Object value : multiValue) {
strValueList.add(String.valueOf(value));
}
}

if (!strValueList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void saveToCache(ServicePolicies policies) {
LOG.error("ServicePolicies is null object!!");
}

LOG.debug("<== RangerServicePoliciesCache(serviceName={}).saveToCache()", policies.getServiceName());
LOG.debug("<== RangerServicePoliciesCache(serviceName={}).saveToCache()", policies != null ? policies.getServiceName() : "<null>");
}

private class ServicePoliciesWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -464,9 +465,11 @@ protected StringBuilder buildWhereClause(SearchCriteria searchCriteria, List<Sea
} else if (searchCriteria.getNotNullParamList().contains(searchField.getClientFieldName())) {
whereClause.append(" and ").append(searchField.getFieldName()).append(" is not null");
} else if (searchField.getDataType() == SearchField.DATA_TYPE.INT_LIST || isListValue && searchField.getDataType() == SearchField.DATA_TYPE.INTEGER) {
Collection<Number> intValueList;
final Collection<Number> intValueList;

if ((paramValue instanceof Integer || paramValue instanceof Long)) {
if (paramValue == null) {
intValueList = Collections.emptyList();
} else if (paramValue instanceof Integer || paramValue instanceof Long) {
intValueList = new ArrayList<>();

intValueList.add((Number) paramValue);
Expand Down Expand Up @@ -613,9 +616,11 @@ protected void resolveQueryParams(Query query, SearchCriteria searchCriteria, Li
if (searchCriteria.getNullParamList().contains(searchField.getClientFieldName()) || searchCriteria.getNotNullParamList().contains(searchField.getClientFieldName())) { //NOPMD
// Already addressed while building where clause
} else if (searchField.getDataType() == SearchField.DATA_TYPE.INT_LIST || isListValue && searchField.getDataType() == SearchField.DATA_TYPE.INTEGER) {
Collection<Number> intValueList;
final Collection<Number> intValueList;

if ((paramValue instanceof Integer || paramValue instanceof Long)) {
if (paramValue == null) {
intValueList = Collections.emptyList();
} else if (paramValue instanceof Integer || paramValue instanceof Long) {
intValueList = new ArrayList<>();

intValueList.add((Number) paramValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,6 @@ private void init(EntityManager em) {
BATCH_DELETE_BATCH_SIZE = DEFAULT_BATCH_DELETE_BATCH_SIZE;
}

logger.info(PROP_BATCH_DELETE_BATCH_SIZE + "=" + BATCH_DELETE_BATCH_SIZE);
logger.info("{}={}", PROP_BATCH_DELETE_BATCH_SIZE, BATCH_DELETE_BATCH_SIZE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public List<XXAuthSession> getAuthSessionByUserId(Long userId) {
}

public long getRecentAuthFailureCountByLoginId(String loginId, int timeRangezSecond) {
Date authWindowStartTime = new Date(DateUtil.getUTCDate().getTime() - timeRangezSecond * 1000L);
Date utcDate = DateUtil.getUTCDate();
Date authWindowStartTime = new Date((utcDate != null ? utcDate.getTime() : System.currentTimeMillis()) - timeRangezSecond * 1000L);

return getEntityManager()
.createNamedQuery("XXAuthSession.getRecentAuthFailureCountByLoginId", Long.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ public VXAccessAuditList searchXAccessAudits(SearchCriteria searchCriteria) {

returnList.setPageSize(searchCriteria.getMaxRows());
returnList.setResultSize(response.getHits().getHits().length);
returnList.setTotalCount(response.getHits().getTotalHits().value);

if (response.getHits().getTotalHits() != null) {
returnList.setTotalCount(response.getHits().getTotalHits().value);
}

returnList.setStartIndex(searchCriteria.getStartIndex());
returnList.setVXAccessAudits(xAccessAuditList);

Expand Down
Loading

0 comments on commit 8f9bedf

Please sign in to comment.