Skip to content

Commit b4f8ffd

Browse files
committed
Address Gemini review: guard primaryConstructor against empty ctors
If Class.getConstructors() returns empty (e.g. all public constructors removed in a future Spark version), throw an IllegalStateException with the class name instead of letting ctors[0] surface as a cryptic ArrayIndexOutOfBoundsException during static initialization.
1 parent 6b39e98 commit b4f8ffd

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/translation/helpers

‎runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/translation/helpers/EncoderFactory.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class EncoderFactory {
4646
@SuppressWarnings("unchecked")
4747
private static <T> Constructor<T> primaryConstructor(Class<T> cls) {
4848
Constructor<?>[] ctors = cls.getConstructors();
49+
if (ctors.length == 0) {
50+
throw new IllegalStateException("No public constructors found for " + cls.getName());
51+
}
4952
Constructor<?> widest = ctors[0];
5053
for (int i = 1; i < ctors.length; i++) {
5154
if (ctors[i].getParameterCount() > widest.getParameterCount()) {

0 commit comments

Comments
 (0)