Devin Fisher created NIFI-16623:
-----------------------------------

             Summary: MockProcessContext.clearProperties() throws 
ConcurrentModificationException for processors with only dynamic properties
                 Key: NIFI-16623
                 URL: https://issues.apache.org/jira/browse/NIFI-16623
             Project: Apache NiFi
          Issue Type: Bug
          Components: NiFi API
    Affects Versions: 2.12.0
            Reporter: Devin Fisher


{{MockProcessContext.clearProperties()}} iterates the map returned by 
{{getProperties()}} and calls {{removeProperty()}} on each entry. 
{{removeProperty()}} deletes from the context's {{properties}} {{{}HashMap{}}}.

When {{getPropertyDescriptors()}} is empty, {{getProperties()}} returns 
{{{}Collections.unmodifiableMap(properties){}}}, a view of that same 
{{{}HashMap{}}}. The first removal changes the map. The iterator's next step 
then throws {{{}ConcurrentModificationException{}}}. One property does not 
throw, because the iterator is already finished. Two or more do.

Processors that declare no supported descriptors and are configured with 
dynamic properties hit this. 
{{StandardProcessorTestRunner.migrateProperties()}} calls {{clearProperties()}} 
after those properties are set, so any {{TestRunner}} test that calls 
{{migrateProperties()}} on such a processor fails during setup.

*Reproduce:*
{code:java}
@Test
void 
migratePropertiesThrowsWhileClearingTwoPropertiesOnAProcessorWithNoDescriptors()
{
  TestRunner runner = TestRunners.newTestRunner( new AbstractProcessor()
  {
    @Override
    public void onTrigger( ProcessContext context, ProcessSession session )
    {
    }
  } );

  runner.setProperty( "MsgId", "msg-id" );
  runner.setProperty( "MsgSource", "msg-source" );

  runner.migrateProperties();
}
{code}
 
{{AbstractProcessor}} reports an empty supported-descriptor list. The two 
{{setProperty}} calls are stored as dynamic properties.

Expected: {{migrateProperties()}} clears the two properties and continues.

Actual: {{java.util.ConcurrentModificationException}} from 
{{{}HashMap$HashIterator.nextNode{}}}, at 
{{{}MockProcessContext.clearProperties{}}}.

 

 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to