Skip to content

Commit 76b3105

Browse files
committed
HHH-18875 Avoid need for refletive registrations triggered by StandardStack's custom implementation
1 parent 61d0a81 commit 76b3105

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/collections/StandardStack.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package org.hibernate.internal.util.collections;
66

7-
import java.lang.reflect.Array;
87
import java.util.Arrays;
98
import java.util.NoSuchElementException;
109
import java.util.function.BiFunction;
@@ -21,24 +20,34 @@
2120
* @author Marco Belladelli
2221
*/
2322
public final class StandardStack<T> implements Stack<T> {
24-
private T[] elements;
23+
24+
private Object[] elements;
2525
private int top = 0;
2626

27-
private Class<T> type;
27+
public StandardStack() {
28+
}
2829

30+
public StandardStack(T initialValue) {
31+
push( initialValue );
32+
}
33+
34+
/**
35+
* @deprecated use the default constructor instead
36+
*/
37+
@Deprecated(forRemoval = true)
2938
public StandardStack(Class<T> type) {
30-
this.type = type;
3139
}
3240

41+
/**
42+
* @deprecated use {@link #StandardStack(Object)} instead.
43+
*/
44+
@Deprecated(forRemoval = true)
3345
public StandardStack(Class<T> type, T initial) {
34-
this( type );
3546
push( initial );
3647
}
3748

38-
@SuppressWarnings("unchecked")
3949
private void init() {
40-
elements = (T[]) Array.newInstance( type, 8 );
41-
type = null;
50+
elements = new Object[8];
4251
}
4352

4453
@Override
@@ -57,7 +66,7 @@ public T pop() {
5766
if ( isEmpty() ) {
5867
throw new NoSuchElementException();
5968
}
60-
T e = elements[--top];
69+
T e = (T) elements[--top];
6170
elements[top] = null;
6271
return e;
6372
}
@@ -67,23 +76,23 @@ public T getCurrent() {
6776
if ( isEmpty() ) {
6877
return null;
6978
}
70-
return elements[top - 1];
79+
return (T) elements[top - 1];
7180
}
7281

7382
@Override
7483
public T peek(int offsetFromTop) {
7584
if ( isEmpty() ) {
7685
return null;
7786
}
78-
return elements[top - offsetFromTop - 1];
87+
return (T) elements[top - offsetFromTop - 1];
7988
}
8089

8190
@Override
8291
public T getRoot() {
8392
if ( isEmpty() ) {
8493
return null;
8594
}
86-
return elements[0];
95+
return (T) elements[0];
8796
}
8897

8998
@Override
@@ -107,14 +116,14 @@ public void clear() {
107116
@Override
108117
public void visitRootFirst(Consumer<T> action) {
109118
for ( int i = 0; i < top; i++ ) {
110-
action.accept( elements[i] );
119+
action.accept( (T) elements[i] );
111120
}
112121
}
113122

114123
@Override
115124
public <X> X findCurrentFirst(Function<T, X> function) {
116125
for ( int i = top - 1; i >= 0; i-- ) {
117-
final X result = function.apply( elements[i] );
126+
final X result = function.apply( (T) elements[i] );
118127
if ( result != null ) {
119128
return result;
120129
}
@@ -125,7 +134,7 @@ public <X> X findCurrentFirst(Function<T, X> function) {
125134
@Override
126135
public <X, Y> X findCurrentFirstWithParameter(Y parameter, BiFunction<T, Y, X> biFunction) {
127136
for ( int i = top - 1; i >= 0; i-- ) {
128-
final X result = biFunction.apply( elements[i], parameter );
137+
final X result = biFunction.apply( (T) elements[i], parameter );
129138
if ( result != null ) {
130139
return result;
131140
}
@@ -138,4 +147,5 @@ private void grow() {
138147
final int jump = ( oldCapacity < 64 ) ? ( oldCapacity + 2 ) : ( oldCapacity >> 1 );
139148
elements = Arrays.copyOf( elements, oldCapacity + jump );
140149
}
150+
141151
}

0 commit comments

Comments
 (0)