#vulnerable code 
                                @Override
    protected void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush)  {
        if (socket == null) {
            if (connector != null && !immediateFail) {
                connector.latch();
            }
            if (socket == null) {
                final String msg = "Error writing to " + getName() + " socket not available";
                throw new AppenderLoggingException(msg);
            }
        }
        synchronized (this) {
            try {
                final OutputStream outputStream = getOutputStream();
                outputStream.write(bytes, offset, length);
                if (immediateFlush) {
                    outputStream.flush();
                }
            } catch (final IOException ex) {
                if (retry && connector == null) {
                    connector = new Reconnector(this);
                    connector.setDaemon(true);
                    connector.setPriority(Thread.MIN_PRIORITY);
                    connector.start();
                }
                final String msg = "Error writing to " + getName();
                throw new AppenderLoggingException(msg, ex);
            }
        }
    } 
                            #location 5 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                @Override
    protected void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush)  {
        if (socket == null) {
            if (reconnector != null && !immediateFail) {
                reconnector.latch();
            }
            if (socket == null) {
                final String msg = "Error writing to " + getName() + " socket not available";
                throw new AppenderLoggingException(msg);
            }
        }
        synchronized (this) {
            try {
                final OutputStream outputStream = getOutputStream();
                outputStream.write(bytes, offset, length);
                if (immediateFlush) {
                    outputStream.flush();
                }
            } catch (final IOException ex) {
                if (retry && reconnector == null) {
                    reconnector = new Reconnector(this);
                    reconnector.setDaemon(true);
                    reconnector.setPriority(Thread.MIN_PRIORITY);
                    reconnector.start();
                }
                final String msg = "Error writing to " + getName();
                throw new AppenderLoggingException(msg, ex);
            }
        }
    }