Source:
<code>public void deploy( BootOptions bootOptions ) throws DeployException { final DeploymentInfo di = indyDeployment.getDeployment( bootOptions.getContextPath() ).setContextPath( "/" ); final DeploymentManager dm = Servlets.defaultContainer().addDeployment( di ); Collection<String> list = Servlets.defaultContainer().listDeployments(); logger.info( "List deployments: {}", list ); dm.deploy(); try { Integer port = bootOptions.getPort(); if ( port < 1 ) { logger.info( "Looking for open Undertow port..." ); <START> final ThreadLocal<ServletException> errorHolder = new ThreadLocal<>(); <END> ThreadLocal<Integer> usingPort = new ThreadLocal<>(); server = PortFinder.findPortFor( 16, ( foundPort ) -> { Undertow undertow = null; try { EncodingHandler eh = getGzipEncodeHandler( dm ); undertow = Undertow.builder() .setHandler( eh ) .addHttpListener( foundPort, bootOptions.getBind() ) .build(); undertow.start(); usingPort.set( foundPort ); } catch ( ServletException e ) { errorHolder.set( e ); } return undertow; } ); ServletException e = errorHolder.get(); if ( e != null ) { throw e; } bootOptions.setPort( usingPort.get() ); } else { logger.info( "Start Undertow server, bind: {}, port: {}", bootOptions.getBind(), port ); server = Undertow.builder() .setHandler( getGzipEncodeHandler( dm ) ) .addHttpListener( port, bootOptions.getBind() ) .build(); server.start(); } logger.info( "Indy listening on {}:{}\n\n", bootOptions.getBind(), bootOptions.getPort() ); } catch ( Exception e ) { logger.error( "Deploy failed", e ); throw new DeployException( "Deploy failed", e ); } }</code><technical_language>AtomicReference instead of ThreadLocal</technical_language>

Target:
public void deploy( BootOptions bootOptions ) throws DeployException { final DeploymentInfo di = indyDeployment.getDeployment( bootOptions.getContextPath() ).setContextPath( "/" ); final DeploymentManager dm = Servlets.defaultContainer().addDeployment( di ); Collection<String> list = Servlets.defaultContainer().listDeployments(); logger.info( "List deployments: {}", list ); dm.deploy(); try { Integer port = bootOptions.getPort(); if ( port < 1 ) { logger.info( "Looking for open Undertow port..." ); final AtomicReference<ServletException> errorHolder = new AtomicReference<>(); AtomicReference<Integer> usingPort = new AtomicReference<>(); server = PortFinder.findPortFor( 16, ( foundPort ) -> { Undertow undertow = null; try { EncodingHandler eh = getGzipEncodeHandler( dm ); undertow = Undertow.builder() .setHandler( eh ) .addHttpListener( foundPort, bootOptions.getBind() ) .build(); undertow.start(); usingPort.set( foundPort ); } catch ( ServletException e ) { errorHolder.set( e ); } return undertow; } ); ServletException e = errorHolder.get(); if ( e != null ) { throw e; } bootOptions.setPort( usingPort.get() ); } else { logger.info( "Start Undertow server, bind: {}, port: {}", bootOptions.getBind(), port ); server = Undertow.builder() .setHandler( getGzipEncodeHandler( dm ) ) .addHttpListener( port, bootOptions.getBind() ) .build(); server.start(); } logger.info( "Indy listening on {}:{}\n\n", bootOptions.getBind(), bootOptions.getPort() ); } catch ( Exception e ) { logger.error( "Deploy failed", e ); throw new DeployException( "Deploy failed", e ); } }