[KYUUBI #7697] Reject hiddenImpl on a DynConstructors builder without a base class - #7698
Open
LuciferYang wants to merge 1 commit into
Open
Conversation
…ithout a base class DynConstructors.builder() leaves baseClass null, and the zero-argument hiddenImpl(Class...) overload forwarded that null to hiddenImpl(Class, Class...), which called getDeclaredConstructor on it and threw NullPointerException from inside the builder chain. Nothing in the failure said the builder had no base class to look up. Throw IllegalStateException naming the condition instead, after the same ctor != null short-circuit every sibling overload has, so a class-less builder that already matched keeps working. Reaching this overload takes either no arguments or an explicit Class<?>[], which is also what a Scala : _* splat passes; a loose Class argument binds to hiddenImpl(Class, Class...) with that class as the target. iceberg-common deprecated the overload in 1.6.0 and removed it in 1.7.0 over that ambiguity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are the changes needed?
Closes #7697.
DynConstructors.builder()leavesbaseClassnull, and the zero-argumenthiddenImpl(Class<?>... types)forwarded that field intohiddenImpl(Class, Class...), which callstargetClass.getDeclaredConstructor(types)and catches onlySecurityExceptionandNoSuchMethodException. The null escaped as a bare NPE from inside the builder chain, with no mention of a missing base class. A builder that never named a class asking for a hidden constructor in its base class has no correct reading, so the patch rejects the call. AGENTS.md asks for a throw on unsupported usage rather than a silent skip, andIllegalStateExceptionis what this file already uses when a call does not fit the receiver's state:Ctor.bindthrows it for "Cannot bind constructors".A loose
Classargument does not reach that overload:builder().hiddenImpl(Foo.class)bindshiddenImpl(Class, Class...)withFooas the target. What reaches it is a call with no arguments, or one passing an explicitClass<?>[], which is what a Scala: _*splat compiles to and is the shapeReflectUtilsalready uses against theDynMethodsbuilder.Nothing in Kyuubi reaches it either.
hiddenImpl()has no caller outside the new tests, and the twenty-odd production sites that build without a class all continue with one of theimploverloads. This is hygiene on a retained upstream API, not a field failure being fixed.There is a second option a maintainer may prefer: drop the overload, as iceberg-common did in 1.7.0 (apache/iceberg#10818) after deprecating it in 1.6.0 over the same varargs conflict. That is not free, though: a caller passing an explicit array, or a Scala splat, binds here today, so removal is a source break for them even if nothing in this repository notices. Keeping the overload means carrying this guard and its explanation indefinitely. Removing a public method from a published module is a maintainer call rather than mine; #7689 put the same choice to reviewers for
DynMethods.ctorImpl.Two scope notes. The guard sits below the
ctor != nullshort-circuit that opens every otherimplandhiddenImploverload, so a class-less builder that already matched keeps working:builder().impl("java.lang.String").hiddenImpl()builds before this patch and still builds after. Placed above the short-circuit it would start throwing. And the genericCannot find constructor for nullthat a class-less builder reports when all its name-based lookups miss is untouched;hiddenImpl()no longer reaches it, and improving that message belongs with theproblemsdiagnostics work.How was this patch tested?
Two tests in
DynConstructorsTest, one per half of the contract.testHiddenImplWithoutBaseClassFailsFastasserts thatbuilder().hiddenImpl()throwsIllegalStateExceptionwhose message says the builder has no base class. Againstorigin/master'sDynConstructorsit goes red withUnexpected exception type thrown, expected: <java.lang.IllegalStateException> but was: <java.lang.NullPointerException>, that NPE beingCannot invoke "java.lang.Class.getDeclaredConstructor(java.lang.Class[])" because "targetClass" is null.testHiddenImplWithoutBaseClassIsSkippedOnceFoundbuildsbuilder().impl("java.lang.String").hiddenImpl().buildChecked()and asserts the constructed class isString. It pins the guard's placement rather than restating the first test: with the null check moved above thector != nullshort-circuit, it fails withIllegalStateException.6 of 6 green and spotless clean. Both revert checks above ran against a copy of the pre-fix class compiled outside the repository.
Was this patch assisted by generative AI tooling?
Assisted-by: Claude Opus 5