[ 
https://issues.apache.org/jira/browse/FLINK-39687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18081761#comment-18081761
 ] 

袁焊忠 commented on FLINK-39687:
-----------------------------

I can take this one.

I'll keep the change focused on the SQL Gateway SessionContext dependency 
handling path. My plan is to add a regression test that exercises a 
DefaultContext with a non-empty dependency list, verify the current 
ArrayStoreException behavior, and then convert the URI values to URL values 
explicitly before building the classloader.

I'll include the focused Maven test results in the pull request once the fix is 
ready.

> URI used as URL in SessionContext causes ArrayStoreException
> ------------------------------------------------------------
>
>                 Key: FLINK-39687
>                 URL: https://issues.apache.org/jira/browse/FLINK-39687
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Gateway
>            Reporter: tonyabasy
>            Priority: Major
>
> h2. Location
> {{flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/context/SessionContext.java}}
>  line 306
> h2. Faulty Code
> {code:java}
> defaultContext.getDependencies().toArray(new URL[0]) {code}
> h2. Root Cause
> {{DefaultContext.getDependencies()}} returns {{List<URI>}} 
> ({{{}java.net.URI{}}}), but the code calls {{{}.toArray(new URL[0]){}}}.
> {{java.net.URI}} and {{java.net.URL}} are *completely unrelated classes* (no 
> inheritance relationship), so a {{URL[]}} array cannot hold {{URI}} objects.
> Java's {{List.toArray(T[])}} generic method does not check element type 
> compatibility at compile time, so this compiles successfully. However, it 
> will *always throw {{ArrayStoreException}} at runtime* when the {{toArray}} 
> implementation attempts to store a {{URI}} into a {{{}URL[]{}}}.
> h2. When It Triggers
> This bug triggers when {{defaultContext.getDependencies()}} returns a 
> non-empty list. It currently goes unnoticed because:
>  * {{DefaultContext.load()}} creates a DefaultContext with an empty 
> dependency list (the {{dependencies}} parameter is always empty in current 
> callers)
>  * {{ScriptRunner}} passes {{Collections.emptyList()}} directly (empty array, 
> {{toArray}} never needs to store elements, so no exception)
> Once anyone creates a DefaultContext with non-empty dependencies, the 
> exception will fire.
> h2. Fix
> Convert each {{URI}} to {{URL}} individually:
> {code:java}
> defaultContext.getDependencies().stream()
>     .map(uri -> uri.toURL())
>     .toArray(URL[]::new) {code}
> h2. Introduced In
> FLINK 2.2.0 (commit: 5a336892424)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to