You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2020/06/02 16:15:00 UTC
[jira] [Commented] (NIFI-7447) Objects returned from Controller
Services may be invoked with the wrong ClassLoader
[ https://issues.apache.org/jira/browse/NIFI-7447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17123992#comment-17123992 ]
ASF subversion and git services commented on NIFI-7447:
-------------------------------------------------------
Commit e31c323aa70dfe8f1bc7a3f39c216f9154529654 in nifi's branch refs/heads/master from Mark Payne
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=e31c323 ]
NIFI-7447: When returning an object from a Controller Service, if that object is defined as an interface, proxy that interface. This way, any method call into the object will also change the classloader to the appropriate classloader.
> Objects returned from Controller Services may be invoked with the wrong ClassLoader
> -----------------------------------------------------------------------------------
>
> Key: NIFI-7447
> URL: https://issues.apache.org/jira/browse/NIFI-7447
> Project: Apache NiFi
> Issue Type: Bug
> Components: Core Framework
> Reporter: Mark Payne
> Assignee: Mark Payne
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> When a Processor calls a Controller Service, the framework changes the Thread's Context ClassLoader from the Processor's ClassLoader to the Controller Service's ClassLoader. This works well. However, when the object that is returned from a Controller Service has a method invoked, the Context ClassLoader is that of the Processor.
> This means that if the object returned attempts to load a class when its method is invoked, it's attempting to load it from the wrong ClassLoader. This can result in NoClassDefFoundError/ClassNotFoundException, etc.
> An example from the mailing list:
> ---------
> Hello,
>
> I try to implement a groovy script where I'm using jsonOutput.
> With nifi 1.5 the script works, but If I'm try to use the same groovy script with nifi 1.11.4, I get
> "unable to load FastStringService"
>
> example code :
>
> class GroovyRecordSetWriter implements RecordSetWriter {
> ....
> @Override
> WriteResult write(Record r) throws IOException {
> ...
> def j = JsonOutput.toJson([name: 'John Doe', age: 42])
> out.write(j.getBytes())
>
> ...
> ---------
>
> The problem here is that Controller Service returns a GroovyRecordSetWriter. When the processor calls #write, the Context Class Loader is the Processor's Context Class Loader, which knows nothing about Groovy. The call then delegates to `JsonOutput.toJson`. When this happens, Groovy, under the hood, attempts to load the `FastStringService` class using the Context Class Loader, which of course fails since the Context Class Loader is the Processor's ClassLoader and not the ScriptedRecordSetWriter's ClassLoader.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)