[ 
https://issues.apache.org/jira/browse/CAMEL-16494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Valeriy Ak updated CAMEL-16494:
-------------------------------
    Description: 
After camel context failed to start with VetoCamelContextStartException ones, 
it never can be started again.

It happens becauce *vetoed* field checked in  AbstractCamelContext.init() 
method.  This method throw RuntimeException  (even if rethrowException = false, 
because called fail(vetoed)) if vetoed is not null.

And *vetoed* field is cleaned in method doStartContext.

 

AbstractCamelContext code:
{code:java}
init(); //<--- this method throws RuntimeException when vetoed != null
try (AutoCloseable ignored = doLifecycleChange()) {
    status = STARTING;
    LOG.trace("Starting service: {}", this);
    doStart();  //<-- this method sets vetoed == null{code}
 

Example for reproduce:
{code:java}
import org.apache.camel.CamelContext;
import org.apache.camel.VetoCamelContextStartException;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.LifecycleStrategySupport;

public class CamelContextVetoExceptionBug {
    public static void main(String[] args) {
        CamelContext context = new DefaultCamelContext();

        boolean[] needThrow = new boolean[]{true};
        context.addLifecycleStrategy(new LifecycleStrategySupport() {
            @Override
            public void onContextStarting(CamelContext context) throws 
VetoCamelContextStartException {
                if (needThrow[0]) {
                    needThrow[0] = false;
                    throw new VetoCamelContextStartException("Veto 
onContextStarting", context, false);
                }
            }
        });
        context.start();
        System.out.println("Start failed without rethrow: veto=" + 
context.isVetoStarted());


        try {
            context.start();
        } catch (Exception e) {
            System.out.println("Exception: veto=" + context.isVetoStarted());
        }
    }
} {code}
 

Expected behavior:
 * next context start does not thow RuntimeException
 * next context start - started context

 

  was:
After camel context failed started with VetoCamelContextStartException ones, it 
never can be started again.

It happens becauce *vetoed* field checked in  AbstractCamelContext.init() 
method.  This method throw RuntimeException  (even if rethrowException = false, 
because called fail(vetoed)) if vetoed is not null.

And *vetoed* field is cleaned in method doStartContext.

 

AbstractCamelContext code:
{code:java}
init(); //<--- this method throws RuntimeException when vetoed != null
try (AutoCloseable ignored = doLifecycleChange()) {
    status = STARTING;
    LOG.trace("Starting service: {}", this);
    doStart();  //<-- this method sets vetoed == null{code}
 

Example for reproduce:
{code:java}
import org.apache.camel.CamelContext;
import org.apache.camel.VetoCamelContextStartException;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.LifecycleStrategySupport;

public class CamelContextVetoExceptionBug {
    public static void main(String[] args) {
        CamelContext context = new DefaultCamelContext();

        boolean[] needThrow = new boolean[]{true};
        context.addLifecycleStrategy(new LifecycleStrategySupport() {
            @Override
            public void onContextStarting(CamelContext context) throws 
VetoCamelContextStartException {
                if (needThrow[0]) {
                    needThrow[0] = false;
                    throw new VetoCamelContextStartException("Veto 
onContextStarting", context, false);
                }
            }
        });
        context.start();
        System.out.println("Start failed without rethrow: veto=" + 
context.isVetoStarted());


        try {
            context.start();
        } catch (Exception e) {
            System.out.println("Exception: veto=" + context.isVetoStarted());
        }
    }
} {code}
 

Expected behavior:
 * next context start does not thow RuntimeException
 * next context start - started context


> After VetoCamelContextStartException CamelContext instance broken forever
> -------------------------------------------------------------------------
>
>                 Key: CAMEL-16494
>                 URL: https://issues.apache.org/jira/browse/CAMEL-16494
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 3.7.3
>            Reporter: Valeriy Ak
>            Priority: Major
>
> After camel context failed to start with VetoCamelContextStartException ones, 
> it never can be started again.
> It happens becauce *vetoed* field checked in  AbstractCamelContext.init() 
> method.  This method throw RuntimeException  (even if rethrowException = 
> false, because called fail(vetoed)) if vetoed is not null.
> And *vetoed* field is cleaned in method doStartContext.
>  
> AbstractCamelContext code:
> {code:java}
> init(); //<--- this method throws RuntimeException when vetoed != null
> try (AutoCloseable ignored = doLifecycleChange()) {
>     status = STARTING;
>     LOG.trace("Starting service: {}", this);
>     doStart();  //<-- this method sets vetoed == null{code}
>  
> Example for reproduce:
> {code:java}
> import org.apache.camel.CamelContext;
> import org.apache.camel.VetoCamelContextStartException;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.support.LifecycleStrategySupport;
> public class CamelContextVetoExceptionBug {
>     public static void main(String[] args) {
>         CamelContext context = new DefaultCamelContext();
>         boolean[] needThrow = new boolean[]{true};
>         context.addLifecycleStrategy(new LifecycleStrategySupport() {
>             @Override
>             public void onContextStarting(CamelContext context) throws 
> VetoCamelContextStartException {
>                 if (needThrow[0]) {
>                     needThrow[0] = false;
>                     throw new VetoCamelContextStartException("Veto 
> onContextStarting", context, false);
>                 }
>             }
>         });
>         context.start();
>         System.out.println("Start failed without rethrow: veto=" + 
> context.isVetoStarted());
>         try {
>             context.start();
>         } catch (Exception e) {
>             System.out.println("Exception: veto=" + context.isVetoStarted());
>         }
>     }
> } {code}
>  
> Expected behavior:
>  * next context start does not thow RuntimeException
>  * next context start - started context
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to