You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by "phrocker (via GitHub)" <gi...@apache.org> on 2024/03/05 22:15:25 UTC
[I] Set.Of will throw Illegal argument Exception [accumulo-access]
phrocker opened a new issue, #66:
URL: https://github.com/apache/accumulo-access/issues/66
https://github.com/apache/accumulo-access/blob/2da31d3643916c020b14c9e61fa632543dbc56b7/src/main/java/org/apache/accumulo/access/Authorizations.java#L67
Set.of will throw an IllegalArgumentException as expected, but as a consumer to the API we should avoid the exception and prune duplicates .
Would love thoughts. I think it's reasonable to suggest that the client of the Authorizations API should do this work.
I'll submit a PR for this trivial change if there is any concurrence from @keith-turner or @dlmarion that we can de-dupe in the of helper method in Authorization
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Duplicate authorization will throw an Illegal Argument Exception [accumulo-access]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on issue #66:
URL: https://github.com/apache/accumulo-access/issues/66#issuecomment-1979753029
@phrocker - do you know if `Set.copyOf` does the same?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Duplicate authorization will throw an Illegal Argument Exception [accumulo-access]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on issue #66:
URL: https://github.com/apache/accumulo-access/issues/66#issuecomment-1979758535
The other API objects have good javadoc coverage, I wonder if that's what is missing here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Duplicate authorization will throw an Illegal Argument Exception [accumulo-access]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on issue #66:
URL: https://github.com/apache/accumulo-access/issues/66#issuecomment-1979826812
I did not realize Set.of would throw an exception when there are dupes. We could do the following in the impl
```java
public static Authorizations of(String... authorizations) {
return new Authorizations(Set.copyOf(Arrays.asList(authorizations));
}
```
`Arrays.asList()` wraps the array and does not copy it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Duplicate authorization will throw an Illegal Argument Exception [accumulo-access]
Posted by "phrocker (via GitHub)" <gi...@apache.org>.
phrocker commented on issue #66:
URL: https://github.com/apache/accumulo-access/issues/66#issuecomment-1979767650
> The other API objects have good javadoc coverage, I wonder if that's what is missing here.
I think that is fair. If I knew this beforehand I would have guarded against it.
Apache Accumulo leverages a hashset which guards against [this with the linked code](https://github.com/apache/accumulo/blob/main/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java#L134):
``` java
private static Set<ByteSequence> createInternalSet(int size) {
if (size < 1) {
return EMPTY_AUTH_SET;
} else {
return new HashSet<>(size);
}
}
private static List<byte[]> createInternalList(int size) {
if (size < 1) {
return EMPTY_AUTH_LIST;
} else {
return new ArrayList<>(size);
}
}
/**
* Constructs an authorization object from a collection of string authorizations that have each
* already been encoded as UTF-8 bytes. Warning: This method does not verify that each encoded
* string is valid UTF-8.
*
* @param authorizations collection of authorizations, as strings encoded in UTF-8
* @throws IllegalArgumentException if authorizations is null
* @see #Authorizations(String...)
*/
public Authorizations(Collection<byte[]> authorizations) {
checkArgument(authorizations != null, "authorizations is null");
this.auths = createInternalSet(authorizations.size());
this.authsList = createInternalList(authorizations.size());
for (byte[] auth : authorizations) {
auths.add(new ArrayByteSequence(auth));
}
checkAuths();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Duplicate authorization will throw an Illegal Argument Exception [accumulo-access]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion closed issue #66: Duplicate authorization will throw an Illegal Argument Exception
URL: https://github.com/apache/accumulo-access/issues/66
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Duplicate authorization will throw an Illegal Argument Exception [accumulo-access]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on issue #66:
URL: https://github.com/apache/accumulo-access/issues/66#issuecomment-1979782116
[Set.copyOf](https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/java/util/Set.java#L723) also creates a HashSet from the collection, then calls `Set.of`. If we put the responsibility on the user to provide a deduplicated array when calling `Authorizations of(String... authorizations)`, then it's likely that they would use a Set and call `Authorizations of(Collection<String> authorizations)` instead.
I wonder if we should remove the two `of` implementations and do the following. This would reduce the extra HashSet object allocation if we called `Set.copyOf`.
```
public static Authorizations of(HashSet<String> authorizations) {
return new Authorizations(Set.of(authorizations.toArray()));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org