<commit_before>package org.torquebox.core.injection.analysis;

import java.util.Set;

import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jruby.RubyProc;
import org.torquebox.core.component.InjectionRegistry;

public class RuntimeInjectionAnalyzer {


    public RuntimeInjectionAnalyzer(ServiceRegistry serviceRegistry, ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, InjectionAnalyzer analyzer) {
        this.serviceRegistry = serviceRegistry;
        this.serviceTarget = serviceTarget;
        this.deploymentUnit = deploymentUnit;
        this.analyzer = analyzer;
    }

    public Object analyzeAndInject(Object arg) throws Exception {
        System.err.println( "Analyzing: " + arg.getClass() );
        if (arg instanceof RubyProc) {
            RubyProc proc = (RubyProc) arg;
            InjectionRubyByteCodeVisitor visitor = new InjectionRubyByteCodeVisitor( this.analyzer );
            visitor.assumeMarkerSeen();
            this.analyzer.analyze( proc, visitor );
            Set<Injectable> injectables = visitor.getInjectables();
            InjectionRegistry registry = new InjectionRegistry();
            for (Injectable each : injectables) {
                ServiceName eachName = each.getServiceName( this.serviceTarget, this.deploymentUnit );
                System.err.println( "SERVICE_NAME: " + eachName );
                ServiceController<?> controller = this.serviceRegistry.getRequiredService( eachName );
                System.err.println( "SERVICE_CONTROLLER: " + controller );
                Object injectedValue = null;
                ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
                try {
                    Thread.currentThread().setContextClassLoader( proc.getRuntime().getJRubyClassLoader().getParent() );
                    injectedValue = controller.getValue();   
                } finally {
                    Thread.currentThread().setContextClassLoader( originalCl );
                }
                System.err.println( "SERVICE_VALUE: " + injectedValue );
                System.err.println( "KEY: " + each.getKey() );
                registry.getInjector( each.getKey() ).inject( injectedValue );
            }
            registry.merge( proc.getRuntime() );
        }
        return null;
    }

    private ServiceRegistry serviceRegistry;
    private ServiceTarget serviceTarget;
    private DeploymentUnit deploymentUnit;
    private InjectionAnalyzer analyzer;

}<commit_msg>Seems the println is triggering the classloader error, so moving inside the try block.<commit_after>package org.torquebox.core.injection.analysis;

import java.util.Set;

import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jruby.RubyProc;
import org.torquebox.core.component.InjectionRegistry;

public class RuntimeInjectionAnalyzer {


    public RuntimeInjectionAnalyzer(ServiceRegistry serviceRegistry, ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, InjectionAnalyzer analyzer) {
        this.serviceRegistry = serviceRegistry;
        this.serviceTarget = serviceTarget;
        this.deploymentUnit = deploymentUnit;
        this.analyzer = analyzer;
    }

    public Object analyzeAndInject(Object arg) throws Exception {
        System.err.println( "Analyzing: " + arg.getClass() );
        if (arg instanceof RubyProc) {
            RubyProc proc = (RubyProc) arg;
            InjectionRubyByteCodeVisitor visitor = new InjectionRubyByteCodeVisitor( this.analyzer );
            visitor.assumeMarkerSeen();
            this.analyzer.analyze( proc, visitor );
            Set<Injectable> injectables = visitor.getInjectables();
            InjectionRegistry registry = new InjectionRegistry();
            for (Injectable each : injectables) {
                ServiceName eachName = each.getServiceName( this.serviceTarget, this.deploymentUnit );
                System.err.println( "SERVICE_NAME: " + eachName );
                ServiceController<?> controller = this.serviceRegistry.getRequiredService( eachName );
                System.err.println( "SERVICE_CONTROLLER: " + controller );
                Object injectedValue = null;
                ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
                try {
                    Thread.currentThread().setContextClassLoader( proc.getRuntime().getJRubyClassLoader().getParent() );
                    injectedValue = controller.getValue();   
                    System.err.println( "SERVICE_VALUE: " + injectedValue );
                    System.err.println( "KEY: " + each.getKey() );
                    registry.getInjector( each.getKey() ).inject( injectedValue );
                } finally {
                    Thread.currentThread().setContextClassLoader( originalCl );
                }
            }
            registry.merge( proc.getRuntime() );
        }
        return null;
    }

    private ServiceRegistry serviceRegistry;
    private ServiceTarget serviceTarget;
    private DeploymentUnit deploymentUnit;
    private InjectionAnalyzer analyzer;

}
{'fraction_non_alphanumeric': 0.0887584815697781, 'fraction_numerical': 0.0, 'mean_word_length': 2.712729748127978, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4632371', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1342, 'n_words': 273}