From 99ae8d6f12d50af14ffc6e79918872da2eb15a79 Mon Sep 17 00:00:00 2001 From: Bill Oley Date: Thu, 9 Jan 2025 17:51:37 -0500 Subject: [PATCH] MarkingFunctionsFactory.createMarkingFunctions() should not be called as a static initializer (#2288) (#2289) Co-authored-by: Ivan Bella <347158+ivakegg@users.noreply.github.com> --- .../core/query/cachedresults/CacheableQueryRowImpl.java | 1 - .../handler/dateindex/DateIndexDataTypeHandler.java | 4 +--- .../java/datawave/ingest/csv/mr/input/CSVRecordReader.java | 3 +-- .../iterators/FieldIndexCountingIteratorPerVisibility.java | 3 +-- .../core/iterators/GlobalIndexDateSummaryIterator.java | 3 +-- .../datawave/core/iterators/ResultCountingIterator.java | 3 +-- .../main/java/datawave/query/attributes/AttributeBag.java | 7 ++----- .../java/datawave/query/discovery/TermInfoAggregation.java | 5 ++--- .../query/iterators/FieldIndexCountingIterator.java | 4 +--- .../query/metrics/ShardTableQueryMetricHandler.java | 7 +++---- 10 files changed, 13 insertions(+), 27 deletions(-) diff --git a/core/cached-results/src/main/java/datawave/core/query/cachedresults/CacheableQueryRowImpl.java b/core/cached-results/src/main/java/datawave/core/query/cachedresults/CacheableQueryRowImpl.java index ab4673fb274..ce7fd04ef5e 100644 --- a/core/cached-results/src/main/java/datawave/core/query/cachedresults/CacheableQueryRowImpl.java +++ b/core/cached-results/src/main/java/datawave/core/query/cachedresults/CacheableQueryRowImpl.java @@ -19,7 +19,6 @@ import datawave.data.type.Type; import datawave.marking.MarkingFunctions; -import datawave.marking.MarkingFunctionsFactory; import datawave.webservice.query.cachedresults.CacheableQueryRow; import datawave.webservice.query.data.ObjectSizeOf; import datawave.webservice.query.util.TypedValue; diff --git a/warehouse/ingest-core/src/main/java/datawave/ingest/mapreduce/handler/dateindex/DateIndexDataTypeHandler.java b/warehouse/ingest-core/src/main/java/datawave/ingest/mapreduce/handler/dateindex/DateIndexDataTypeHandler.java index c4c3da55537..25fa6caee29 100644 --- a/warehouse/ingest-core/src/main/java/datawave/ingest/mapreduce/handler/dateindex/DateIndexDataTypeHandler.java +++ b/warehouse/ingest-core/src/main/java/datawave/ingest/mapreduce/handler/dateindex/DateIndexDataTypeHandler.java @@ -83,8 +83,6 @@ public class DateIndexDataTypeHandler implements DataTypeHandler, public static final String DATEINDEX_TNAME = "date.index.table.name"; public static final String DATEINDEX_LPRIORITY = "date.index.table.loader.priority"; - private static final MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); - // comma delimited = values public static final String DATEINDEX_TYPE_TO_FIELDS = ".date.index.type.to.field.map"; @@ -367,7 +365,7 @@ private Value createDateIndexValue(int shard) { * @return the flattened visibility */ protected byte[] flatten(ColumnVisibility vis) { - return markingFunctions.flatten(vis); + return MarkingFunctions.Factory.createMarkingFunctions().flatten(vis); } public Text getDateIndexTableName() { diff --git a/warehouse/ingest-csv/src/main/java/datawave/ingest/csv/mr/input/CSVRecordReader.java b/warehouse/ingest-csv/src/main/java/datawave/ingest/csv/mr/input/CSVRecordReader.java index 52899115f0d..f09c886b623 100644 --- a/warehouse/ingest-csv/src/main/java/datawave/ingest/csv/mr/input/CSVRecordReader.java +++ b/warehouse/ingest-csv/src/main/java/datawave/ingest/csv/mr/input/CSVRecordReader.java @@ -35,7 +35,6 @@ public class CSVRecordReader extends CSVReaderBase implements EventFixer { private static final Logger log = Logger.getLogger(CSVRecordReader.class); private static final IngestConfiguration ingestConfig = IngestConfigurationFactory.getIngestConfiguration(); - private static final MarkingFunctions markingFunctions = MarkingFunctionsFactory.createMarkingFunctions(); protected String csvEventId; private final Multimap metadataForValidation = ArrayListMultimap.create(100, 1); @@ -128,7 +127,7 @@ protected void decorateEvent() { if (null != this.securityMarkings && !this.securityMarkings.isEmpty()) { event.setSecurityMarkings(securityMarkings); try { - event.setVisibility(markingFunctions.translateToColumnVisibility(securityMarkings)); + event.setVisibility(MarkingFunctionsFactory.createMarkingFunctions().translateToColumnVisibility(securityMarkings)); } catch (MarkingFunctions.Exception e) { log.error("Could not set default ColumnVisibility for the event", e); throw new RuntimeException(e); diff --git a/warehouse/query-core/src/main/java/datawave/core/iterators/FieldIndexCountingIteratorPerVisibility.java b/warehouse/query-core/src/main/java/datawave/core/iterators/FieldIndexCountingIteratorPerVisibility.java index d250133bf40..9fa11756fe3 100644 --- a/warehouse/query-core/src/main/java/datawave/core/iterators/FieldIndexCountingIteratorPerVisibility.java +++ b/warehouse/query-core/src/main/java/datawave/core/iterators/FieldIndexCountingIteratorPerVisibility.java @@ -98,7 +98,6 @@ public class FieldIndexCountingIteratorPerVisibility extends WrappingIterator im private Set columnVisibilities = Sets.newHashSet(); private TreeMap keyCache = null; - protected static final MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); // ------------------------------------------------------------------------- // ------------- Constructors @@ -566,7 +565,7 @@ private Map buildReturnKeys() { ColumnVisibility cv = null; try { // Calculate the columnVisibility for this key from the combiner. - cv = markingFunctions.combine(columnVisibilities); + cv = MarkingFunctions.Factory.createMarkingFunctions().combine(columnVisibilities); } catch (Exception e) { log.error("Could not create combined columnVisibility for the count", e); return null; diff --git a/warehouse/query-core/src/main/java/datawave/core/iterators/GlobalIndexDateSummaryIterator.java b/warehouse/query-core/src/main/java/datawave/core/iterators/GlobalIndexDateSummaryIterator.java index 081a275d2ad..6329697cc99 100644 --- a/warehouse/query-core/src/main/java/datawave/core/iterators/GlobalIndexDateSummaryIterator.java +++ b/warehouse/query-core/src/main/java/datawave/core/iterators/GlobalIndexDateSummaryIterator.java @@ -45,7 +45,6 @@ public class GlobalIndexDateSummaryIterator implements SortedKeyValueIterator returnCache = new TreeMap<>(); protected Set columnVisibilities = Sets.newHashSet(); - private static MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); public GlobalIndexDateSummaryIterator() {} @@ -257,7 +256,7 @@ public Map getKeyValues() throws IOException { Set columnVisibilities = this.columnVisibilitiesMap.get(datatype); // Note that the access controls found in the combined ColumnVisibility will be pulled out appropriately here - ColumnVisibility cv = markingFunctions.combine(columnVisibilities); + ColumnVisibility cv = MarkingFunctions.Factory.createMarkingFunctions().combine(columnVisibilities); // Create a new Key compatible with the shardIndex key format Key k = new Key(this.fieldValue, this.fieldName, this.date + '\0' + datatype, new String(cv.getExpression())); diff --git a/warehouse/query-core/src/main/java/datawave/core/iterators/ResultCountingIterator.java b/warehouse/query-core/src/main/java/datawave/core/iterators/ResultCountingIterator.java index d704738a36c..04027b8beac 100644 --- a/warehouse/query-core/src/main/java/datawave/core/iterators/ResultCountingIterator.java +++ b/warehouse/query-core/src/main/java/datawave/core/iterators/ResultCountingIterator.java @@ -66,7 +66,6 @@ public long read() { private String threadName = null; protected Set columnVisibilities = Sets.newHashSet(); - private static MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); public ResultCountingIterator() { threadName = Thread.currentThread().getName(); @@ -210,7 +209,7 @@ public Value getTopValue() { ColumnVisibility cv = null; try { - cv = markingFunctions.combine(columnVisibilities); + cv = MarkingFunctions.Factory.createMarkingFunctions().combine(columnVisibilities); } catch (MarkingFunctions.Exception e) { log.error("Could not create combined columnVisibility for the count", e); return null; diff --git a/warehouse/query-core/src/main/java/datawave/query/attributes/AttributeBag.java b/warehouse/query-core/src/main/java/datawave/query/attributes/AttributeBag.java index 4278f2235f9..4467808c241 100644 --- a/warehouse/query-core/src/main/java/datawave/query/attributes/AttributeBag.java +++ b/warehouse/query-core/src/main/java/datawave/query/attributes/AttributeBag.java @@ -12,7 +12,6 @@ import datawave.marking.MarkingFunctions; import datawave.marking.MarkingFunctions.Exception; -import datawave.marking.MarkingFunctionsFactory; public abstract class AttributeBag> extends Attribute implements Serializable { @@ -23,10 +22,8 @@ public abstract class AttributeBag> extends Attribute private static final long ONE_DAY_MS = 1000l * 60 * 60 * 24; - protected static final MarkingFunctions markingFunctions = MarkingFunctionsFactory.createMarkingFunctions(); - public MarkingFunctions getMarkingFunctions() { - return markingFunctions; + return MarkingFunctions.Factory.createMarkingFunctions(); } protected AttributeBag() { @@ -83,7 +80,7 @@ protected ColumnVisibility combineAndSetColumnVisibilities(Collection attr : attributes) { columnVisibilities.add(attr.getColumnVisibility()); } - return AttributeBag.markingFunctions.combine(columnVisibilities); + return MarkingFunctions.Factory.createMarkingFunctions().combine(columnVisibilities); } private long updateTimestamps() { diff --git a/warehouse/query-core/src/main/java/datawave/query/discovery/TermInfoAggregation.java b/warehouse/query-core/src/main/java/datawave/query/discovery/TermInfoAggregation.java index a8b82a790a7..960a83e1889 100644 --- a/warehouse/query-core/src/main/java/datawave/query/discovery/TermInfoAggregation.java +++ b/warehouse/query-core/src/main/java/datawave/query/discovery/TermInfoAggregation.java @@ -21,7 +21,6 @@ public class TermInfoAggregation implements Function,Discov private static final Logger log = Logger.getLogger(TermInfoAggregation.class); private Set columnVisibilities = Sets.newHashSet(); - private static MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); private final boolean separateCountsByColumnVisibility; private boolean showReferenceCountInsteadOfTermCount = false; private boolean reverseIndex = false; @@ -74,7 +73,7 @@ public DiscoveredThing apply(Collection from) { chosenCount = showReferenceCountInsteadOfTermCount ? referenceCount : termCount; try { - markingFunctions.translateFromColumnVisibility(ti.vis); // just to test parsing + MarkingFunctions.Factory.createMarkingFunctions().translateFromColumnVisibility(ti.vis); // just to test parsing columnVisibilities.add(ti.vis); // Keep track of counts for individual vis @@ -108,7 +107,7 @@ public DiscoveredThing apply(Collection from) { ColumnVisibility columnVisibility = null; try { - columnVisibility = markingFunctions.combine(columnVisibilities); + columnVisibility = MarkingFunctions.Factory.createMarkingFunctions().combine(columnVisibilities); } catch (Exception e) { log.warn("Invalid columnvisibility after combining!", e); diff --git a/warehouse/query-core/src/main/java/datawave/query/iterators/FieldIndexCountingIterator.java b/warehouse/query-core/src/main/java/datawave/query/iterators/FieldIndexCountingIterator.java index 263dd99ee3d..360f604b258 100644 --- a/warehouse/query-core/src/main/java/datawave/query/iterators/FieldIndexCountingIterator.java +++ b/warehouse/query-core/src/main/java/datawave/query/iterators/FieldIndexCountingIterator.java @@ -91,8 +91,6 @@ public class FieldIndexCountingIterator extends WrappingIterator implements Sort private Set visibilitySet = new HashSet<>(); - protected static final MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); - // ------------------------------------------------------------------------- // ------------- Constructors public FieldIndexCountingIterator() { @@ -588,7 +586,7 @@ private Key buildReturnKey() { } ColumnVisibility cv; try { - cv = markingFunctions.combine(columnVisibilities); + cv = MarkingFunctions.Factory.createMarkingFunctions().combine(columnVisibilities); } catch (MarkingFunctions.Exception e) { log.error("Could not combine visibilities: " + visibilitySet + " " + e); return null; diff --git a/web-services/metrics/src/main/java/datawave/query/metrics/ShardTableQueryMetricHandler.java b/web-services/metrics/src/main/java/datawave/query/metrics/ShardTableQueryMetricHandler.java index 4ce461b03d9..1e067dbdc83 100644 --- a/web-services/metrics/src/main/java/datawave/query/metrics/ShardTableQueryMetricHandler.java +++ b/web-services/metrics/src/main/java/datawave/query/metrics/ShardTableQueryMetricHandler.java @@ -137,7 +137,6 @@ public class ShardTableQueryMetricHandler extends BaseQueryMetricHandler connectorAuthorizationCollection = null; private String connectorAuthorizations = null; - private MarkingFunctions markingFunctions = null; @SuppressWarnings("FieldCanBeLocal") private final String JOB_ID = "job_201109071404_1"; @@ -165,7 +164,6 @@ public ShardTableQueryMetricHandler() { String accumuloPassword = conf.get("AccumuloRecordWriter.password"); byte[] encodedAccumuloPassword = Base64.encodeBase64(accumuloPassword.getBytes()); conf.set("AccumuloRecordWriter.password", new String(encodedAccumuloPassword)); - markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); } @PostConstruct @@ -286,11 +284,12 @@ private Multimap getEntries(AbstractColumnBasedHandler event.setDate(storedQueryMetric.getCreateDate().getTime()); // get security markings from metric, otherwise default to PUBLIC Map markings = updatedQueryMetric.getMarkings(); - if (markingFunctions == null || markings == null || markings.isEmpty()) { + if (markings == null || markings.isEmpty()) { event.setVisibility(new ColumnVisibility(DEFAULT_SECURITY_MARKING)); } else { try { - event.setVisibility(this.markingFunctions.translateToColumnVisibility(markings)); + MarkingFunctions markingFunctions = MarkingFunctions.Factory.createMarkingFunctions(); + event.setVisibility(markingFunctions.translateToColumnVisibility(markings)); } catch (Exception e) { log.error(e.getMessage(), e); event.setVisibility(new ColumnVisibility(DEFAULT_SECURITY_MARKING));