Skip to content

Commit

Permalink
PHOENIX-7417 Remove commons-collections dependency (apache#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
NihalJain authored Nov 8, 2024
1 parent 9e2017f commit 200adaa
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
4 changes: 0 additions & 4 deletions phoenix-core-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
*/
package org.apache.phoenix.util;

import org.apache.commons.collections.IteratorUtils;

import org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
import org.apache.phoenix.thirdparty.com.google.common.collect.Lists;

import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -71,14 +70,15 @@ public static <T> T getSingleton(Class<T> clazz, T defaultInstance) {
public static <T> List get(Class<T> clazz, List<T> defaultInstances) {
Iterator<T> iterator = ServiceLoader.load(clazz).iterator();
if (defaultInstances != null) {
defaultInstances.addAll(IteratorUtils.toList(iterator));
defaultInstances.addAll(Lists.newArrayList(iterator));
} else {
defaultInstances = IteratorUtils.toList(iterator);
defaultInstances = Lists.newArrayList(iterator);
}

return defaultInstances;
}


private synchronized static <T> T resolveSingleton(Class<T> clazz, T defaultInstance) {
ServiceLoader<T> loader = ServiceLoader.load(clazz);
// returns the first registered instance found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
*/
package org.apache.phoenix.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions;
import org.apache.phoenix.thirdparty.com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.phoenix.parse.HintNode;

import java.util.Collections;
Expand Down Expand Up @@ -56,7 +55,7 @@ public String getFullTableName() {
*/
public List<String> getRequiredColumns() {
List<String> allColumns = Lists.newArrayList(selectColumns);
if (!CollectionUtils.isEmpty(selectExpressionColumns)) {
if (selectExpressionColumns != null && !selectExpressionColumns.isEmpty()) {
allColumns.addAll(selectExpressionColumns);
}
return allColumns;
Expand Down Expand Up @@ -148,7 +147,8 @@ public QueryBuilder setLimit(int limit) {

public String build() {
Preconditions.checkNotNull(fullTableName, "Table name cannot be null");
if (CollectionUtils.isEmpty(selectColumns) && StringUtils.isBlank(selectExpression)) {
if ((selectColumns == null || selectColumns.isEmpty())
&& StringUtils.isBlank(selectExpression)) {
throw new IllegalArgumentException("At least one column or select expression must be provided");
}
StringBuilder query = new StringBuilder();
Expand Down
5 changes: 0 additions & 5 deletions phoenix-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,6 @@
<artifactId>HdrHistogram</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.Random;
import java.util.UUID;

import org.apache.commons.collections.CollectionUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
Expand Down Expand Up @@ -454,7 +453,7 @@ private void deleteSnapshotIfExists(String snapshotName) throws Exception {
Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
List<SnapshotDescription> snapshotDescriptions = admin.listSnapshots();
boolean isSnapshotPresent = false;
if (CollectionUtils.isNotEmpty(snapshotDescriptions)) {
if (snapshotDescriptions != null && !snapshotDescriptions.isEmpty()) {
for (SnapshotDescription snapshotDescription : snapshotDescriptions) {
if (snapshotName.equals(snapshotDescription.getName())) {
isSnapshotPresent = true;
Expand Down
1 change: 0 additions & 1 deletion phoenix-tracing-webapp/src/build/trace-server-runnable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<include>com.fasterxml.woodstox:woodstox-core</include>
<include>org.codehaus.woodstox:stax2-api</include>
<include>com.google.guava:guava</include>
<include>commons-collections:commons-collections</include>
<include>commons-cli:commons-cli</include>
</includes>
</dependencySet>
Expand Down
15 changes: 9 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
<snappy.version>0.5</snappy.version>
<commons-codec.version>1.16.0</commons-codec.version>
<htrace.version>3.1.0-incubating</htrace.version>
<collections.version>3.2.2</collections.version>
<jodatime.version>2.10.5</jodatime.version>
<joni.version>2.1.31</joni.version>
<omid.version>1.1.2</omid.version>
Expand Down Expand Up @@ -559,6 +558,15 @@
<bannedImport>org.apache.commons.lang.**</bannedImport>
</bannedImports>
</RestrictImports>
<RestrictImports>
<includeTestCode>true</includeTestCode>
<reason>Commons collection is restricted</reason>
<bannedImports>
<bannedImport>org.apache.commons.collections.**</bannedImport>
<!-- If you really need to use commons-collections 4, add as dependency and remove this ban -->
<bannedImport>org.apache.commons.collections4.**</bannedImport>
</bannedImports>
</RestrictImports>
<RestrictImports>
<includeTestCode>true</includeTestCode>
<reason>Use edu.umd.cs.findbugs.annotations</reason>
Expand Down Expand Up @@ -1684,11 +1692,6 @@
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${collections.version}</version>
</dependency>
<!-- Update transitive dependency to a one without CVEs -->
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
Expand Down

0 comments on commit 200adaa

Please sign in to comment.