Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ public String getViolationDescription(short violationCode) {
return null;
}

static final List<Short> NO_VIOLATIONS = new ArrayList<>();

@Override
public List<Short> check(Environment env, Mutation mutation) {

// fast size check
if (mutation.numBytes() < maxSize) {
return NO_VIOLATIONS;
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change in behavior, which I think we should probably try to avoid, unless... is null documented as a special case?

Alternatively, could replace this with an unmodifiable or immutable list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the javadoc for the super class says to return null when there are no violations.

* Checks a mutation for constraint violations. If the mutation contains no violations, returns
* null. Otherwise, returns a list of violation codes.

}

List<Short> violations = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.accumulo.core.constraints;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.Collections;

Expand All @@ -41,7 +42,7 @@ public void testConstraint() {
// pass constraints
Mutation m = new Mutation("rowId");
m.put("colf", "colq", new Value());
assertEquals(Collections.emptyList(), constraint.check(null, m));
assertNull(constraint.check(null, m));

// test with row id > 1mb
m = new Mutation(oversized);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -92,10 +93,11 @@ private static class MinKeySizeConstraint extends DefaultKeySizeConstraint {
@Override
public List<Short> check(Constraint.Environment env, Mutation mutation) {
List<Short> violations = super.check(env, mutation);
if (!violations.isEmpty()) {
if (violations != null && !violations.isEmpty()) {
return violations;
}

violations = new ArrayList<>();
for (ColumnUpdate cu : mutation.getUpdates()) {
int size = mutation.getRow().length;
size += cu.getColumnFamily().length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.accumulo.core.data.constraints;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.Collections;

Expand All @@ -39,7 +40,7 @@ public void testConstraint() {
// pass constraints
Mutation m = new Mutation("rowId");
m.put("colf", "colq", new Value());
assertEquals(Collections.emptyList(), constraint.check(null, m));
assertNull(constraint.check(null, m));

// test with row id > 1mb
m = new Mutation(oversized);
Expand Down