sonatype-lift[bot] commented on code in PR #1765:
URL: https://github.com/apache/groovy/pull/1765#discussion_r945299722
##########
src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java:
##########
@@ -562,6 +565,181 @@ public static List primitiveArrayToList(Object array) {
return list;
}
+ /**
+ * Allows conversion of arrays into an immutable List view
+ *
+ * @param array an array
+ * @return a List view of the array
+ */
+ public static List primitiveArrayToUnmodifiableList(Object array) {
+ return new ArrayToUnmodifiableListAdapter(array);
+ }
+
+ static class ArrayToUnmodifiableListAdapter implements List {
+ private Object delegate;
+
+ public ArrayToUnmodifiableListAdapter(Object delegate) {
+ Objects.requireNonNull(delegate);
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return Array.getLength(delegate);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ for (Object next : this) {
+ if (next.equals(o)) return true;
+ }
+ return false;
+ }
+
+ private class Itr implements Iterator {
+ private int idx = 0;
+
+ @Override
+ public boolean hasNext() {
+ return idx < size();
+ }
+
+ @Override
+ public Object next() {
+ return get(idx++);
+ }
+ }
+
+ @Override
+ public Iterator iterator() {
+ return new Itr();
+ }
+
+ @Override
+ public Object get(int index) {
+ Object item = Array.get(delegate, index);
+ if (item != null && item.getClass().isArray() &&
item.getClass().getComponentType().isPrimitive()) {
+ item = primitiveArrayToUnmodifiableList(item);
+ }
+ return item;
+ }
+
+ @Override
+ public int indexOf(Object o) {
+ int idx = 0;
+ boolean found = false;
+ while (!found && idx < size()) {
+ found = get(idx).equals(o);
+ if (!found) idx++;
+ }
+ return found ? idx : -1;
+ }
+
+ @Override
+ public int lastIndexOf(Object o) {
+ int idx = size() - 1;
+ boolean found = false;
+ while (!found && idx >= 0) {
+ found = get(idx).equals(o);
Review Comment:
π¬ 2 similar findings have been found in this PR
---
*NULL_DEREFERENCE:* object returned by `get(idx)` could be null and is
dereferenced at line 648.
---
<details><summary><b>Expand here to view all instances of this
finding</b></summary><br/>
<div align="center">
| **File Path** | **Line Number** |
| ------------- | ------------- |
|
src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
|
[599](https://github.com/paulk-asert/groovy/blob/bf85a314ab95e219017e7a22cffaa8c0ca8a3091/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java#L599)|
|
src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
|
[637](https://github.com/paulk-asert/groovy/blob/bf85a314ab95e219017e7a22cffaa8c0ca8a3091/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java#L637)|
<p><a
href="https://lift.sonatype.com/results/github.com/apache/groovy/01GAE92Q895CT83NP3Y8TT8EHM?t=Infer|NULL_DEREFERENCE"
target="_blank">Visit the Lift Web Console</a> to find more details in your
report.</p></div></details>
---
Reply with *"**@sonatype-lift help**"* for info about LiftBot commands.
Reply with *"**@sonatype-lift ignore**"* to tell LiftBot to leave out the
above finding from this PR.
Reply with *"**@sonatype-lift ignoreall**"* to tell LiftBot to leave out all
the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to **refresh** the page to see its
response. [Click here](https://help.sonatype.com/lift/talking-to-lift) to get
to know more about LiftBot commands.
---
Was this a good recommendation?
[ [π Not
relevant](https://www.sonatype.com/lift-comment-rating?comment=314998404&lift_comment_rating=1)
] - [ [π Won't
fix](https://www.sonatype.com/lift-comment-rating?comment=314998404&lift_comment_rating=2)
] - [ [π Not critical, will
fix](https://www.sonatype.com/lift-comment-rating?comment=314998404&lift_comment_rating=3)
] - [ [π Critical, will
fix](https://www.sonatype.com/lift-comment-rating?comment=314998404&lift_comment_rating=4)
] - [ [π Critical, fixing
now](https://www.sonatype.com/lift-comment-rating?comment=314998404&lift_comment_rating=5)
]
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]