avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neeme Praks <ne...@apache.org>
Subject thread safety of BCELWrapperGenerator?
Date Tue, 03 Jun 2003 10:21:46 GMT
Question: is BCELWrapperGenerator supposed to be thread safe? Especially 
.createWrapper(Class) method invocations?
I'm getting some weird errors from BCEL, from time to time, not 
always... So I was wondering... looking at the source, it is quite clear 
that it is not thread safe (usage of m_classGenerator and 
m_codeGenerator outside of synchronized block). But is it supposed to be?
If it is, then I'll just move the relevant sections inside the 
synchronized block, if nobody objects...

Rgds,
Neeme

    public Class createWrapper( final Class classToWrap ) throws Exception
    {
        if ( classToWrap == null )
        {
            final String message = "Class to wrap must not be <null>.";
            throw new IllegalArgumentException( message );
        }

        // Guess work interfaces ...
        final Class[] interfacesToImplement =
            AbstractObjectFactory.guessWorkInterfaces( classToWrap );

        // Get JavaClasses as required by BCEL for the wrapped class and 
its interfaces
        final JavaClass javaClassToWrap = lookupClass( classToWrap );
        final JavaClass[] javaInterfacesToImplement =
            lookupClasses( interfacesToImplement );

        // The name of the wrapper class to be generated
        final String wrapperClassName =
            classToWrap.getName() + WRAPPER_CLASS_SUFFIX;

        // Create BCEL class generator
        m_classGenerator =
            new ClassGen(
                wrapperClassName,
                WRAPPER_SUPERCLASS_NAME,
                null,
                Constants.ACC_FINAL
            |Constants.ACC_PUBLIC
            |Constants.ACC_SUPER,
                extractInterfaceNames( interfacesToImplement ) );

        // Initialize method-field generator
        m_codeGenerator.init(
            wrapperClassName,
            WRAPPER_SUPERCLASS_NAME,
            javaClassToWrap,
            m_classGenerator );

        final byte[] byteCode = buildWrapper( javaInterfacesToImplement );
        // TODO: Check synchronization
        Class generatedClass;
        synchronized ( m_bcelClassLoader )
        {
            m_bcelClassLoader.setByteCode( byteCode );
            generatedClass = m_bcelClassLoader.loadClass( 
wrapperClassName );
            m_bcelClassLoader.clearByteCode();
        }

        return generatedClass;
    }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Mime
View raw message