Double checking retrieval/creation of an object

@param args Optional arguments to pass to {@link #retrieve(Object...)}, {@link #create(Object...)}, and {@link #invalid(Object, Object...)}.
@return A retrieved or created object.
423270
public final T get(Object... args) {
        //Grab a read lock to try retrieving the object
        this.readLock.lock();
        try {

            //See if the object already exists
            T value = this.retrieve(args);
            if (this.invalid(value, args)) {
                //Switch to a write lock
                this.readLock.unlock();
                this.writeLock.lock();
                
                //Check if it exists now, create it if it doesn't
                try {
                    value = this.retrieve(args);
                
                    if (this.invalid(value, args)) {
                        value = this.create(args);
                        
                        if (this.logger.isDebugEnabled()) {
                            this.logger.debug("Created new Object='" + value + "'");
                        }
                    }
                    else if (this.logger.isDebugEnabled()) {
                        this.logger.debug("Using retrieved Object='" + value + "'");
                    }
                }
                finally {
                    //switch back to the read lock
                    this.readLock.lock();
                    this.writeLock.unlock();
                }
            }
            else if (this.logger.isDebugEnabled()) {
                this.logger.debug("Using retrieved Object='" + value + "'");
            }

            return value;
        }
        finally {
            this.readLock.unlock();
        }
    }
389350
public T newInstance(Object... args)
    {
        try
        {
            return type.cast(factoryMethod.invoke(null, args));
        }
        catch (IllegalAccessException e)
        {
            throw ExceptionImposter.imposterize( e );
        }
        catch (InvocationTargetException e)
        {
            throw ExceptionImposter.imposterize( e.getCause() );
        }
    }
1187681
static public String getString(String msg, int arg)
	{
		return getString(msg, new Object[] { Integer.toString(arg) });
	}
521080
public static void main(String[] args) {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            List<SavedSearch> savedSearches = twitter.getSavedSearches();
            for (SavedSearch savedSearch : savedSearches) {
                System.out.println("[name:" + savedSearch.getName() + " query:" + savedSearch.getQuery() + " id:"
                        + savedSearch.getId() + "]");
            }
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to retrieve saved searches: " + te.getMessage());
            System.exit(-1);
        }
    }
1210905
@SafeVarargs
    public static <T> Map<T, T> createMap(T... _args) {
        Map<T, T> map = new HashMap<>();
        if (_args != null) {
            if (_args.length % 2 != 0) {
                throw new IllegalArgumentException("Even number of parameters required to create map: " + Arrays.toString(_args));
            }
            for (int i = 0; i < _args.length;) {
                map.put(_args[i], _args[i + 1]);
                i += 2;
            }
        }
        return map;
    }
805528
public synchronized void loadValue(final ARG_TYPE arg) {
        if (fetchFuture != null) {
            // Cancel thread if it was not yet starter.
            fetchFuture.cancel(false);
            // If thread was cancelled before it was started inform error listeners.
            if (fetchThread != null) {
                fetchThread.interruptAndInformListenersIfNeeded();
            }
        }
        // We use thread instead of pure runnable so we can interrupt loading.
        fetchThread = new LoadThread<RETURN_TYPE, ARG_TYPE>(valueGetter,
                successListener,
                errorListener,
                value, arg, dropValueOnFailure);
        fetchFuture = valueGetterExecutor.submit(fetchThread);
    }
384563
public Object create(String name, Object... args)
    throws ClassNotFoundException,
           NoSuchMethodException,
           IllegalAccessException,
           InstantiationException,
           InvocationTargetException
    {
        try {
            return super.create(name, args);
        } catch (NoSuchMethodException x) {
            Class<?> type = Class.forName(name);
            Object singleton = _singleton.get(name);

            if (singleton != null) {
                return singleton;
            } else {
                Object[] burnedin = _arguments.get(type);
                if (burnedin != null) {
                    Object[] nargs = new Object[burnedin.length + args.length];
                    System.arraycopy(burnedin, 0, nargs, 0, burnedin.length);
                    System.arraycopy(args, 0, nargs, burnedin.length, args.length);
                    return Beans.create(type, nargs);
                } else {
                    throw x;
                }
            }
        }
    }
196202
public static void main(String[] args) {
        if (args.length < 2) { // NOSONAR
            LOGGER.error("There must be at least two arguments");
            return;
        }
        int lastIndex = args.length - 1;
        AllureReportGenerator reportGenerator = new AllureReportGenerator(
                getFiles(Arrays.copyOf(args, lastIndex))
        );
        reportGenerator.generate(new File(args[lastIndex]));
    }
1325666
public OGCGeometry getGeometry(DeferredObject[] args) {
		if (isConstant) {
			if (constantGeometry == null) {
				constantGeometry = getGeometry(args[argIndex]);
			} 
			
			return constantGeometry;
		} else {
			// not constant, so we have to rebuild the geometry
			// on every call
			return getGeometry(args[argIndex]);
		}
	}
430433
public static String objectsToString(Object[] args) {
        if (args == null) {
            return null;
        } else if (args.length == 0) {
            return "[]";
        } else {
            StringBuilder sb = new StringBuilder().append("[");
            for (Object arg : args) {
                sb.append(arg.toString()).append(",");
            }
            sb.setCharAt(sb.length() - 1, ']');
            return sb.toString();
        }
    }
249247
public Throwable getThrowable(Object[] args) {
    Throwable rv = null;
    if (args.length > 0) {
      if (args[args.length - 1] instanceof Throwable) {
        rv = (Throwable) args[args.length - 1];
      }
    }
    return rv;
  }
1118042
public Map<String, String> parseArgs(String[] args) {

        Map<String, String> result = new HashMap<String, String>();
        Set<String> allowedKeys = new HashSet<String>(
            Arrays.asList(PARAM_ADDITIONAL, PARAM_SCRIPT, PARAM_REGISTRY_PORT));
        for (String arg : args) {
            if (arg.startsWith("-")) {
                int eqPos = arg.indexOf("=");
                if (eqPos >= 0) {
                    String key = arg.substring(1, eqPos);
                    if (!allowedKeys.contains(key)) {
                        wrongUsage();
                    }
                    String val = arg.substring(eqPos + 1);
                    result.put(key, val);
                } else {
                    wrongUsage();
                }
            } else {
                wrongUsage();
            }
        }
        return result;
    }
827293
@SuppressWarnings("unchecked")
	public T create(Object[] args)
	{
		for(int i=0, n=args.length; i<n; i++)
		{
			if(arguments[i] instanceof FactoryDefinition.InjectedArgument)
			{
				args[i] = arguments[i].getValue(null);
			}
		}

		try
		{
			return (T) raw.newInstance(args);
		}
		catch(IllegalArgumentException e)
		{
			throw new SerializationException("Unable to create; " + e.getMessage(), e);
		}
		catch(InstantiationException e)
		{
			throw new SerializationException("Unable to create; " + e.getMessage(), e);
		}
		catch(IllegalAccessException e)
		{
			throw new SerializationException("Unable to create; " + e.getMessage(), e);
		}
		catch(InvocationTargetException e)
		{
			throw new SerializationException("Unable to create; " + e.getCause().getMessage(), e.getCause());
		}
	}
660779
public T load(Object ... args) {
        try {
            T item = target.newInstance();
            Map vals = (Map)args[0];
            
            load(item, vals);
            return item;
        }
        catch( InstantiationException e ) {
            throw new CacheManagementException(e);
        }
        catch( IllegalAccessException e ) {
            throw new CacheManagementException(e);
        }
    }
1066205
public static <T> T get(Class<T> clazz, String sql, Object... arg) {
        List<T> list = DBUtils.getList(clazz, sql, arg);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
970888
public static void main2(String args[]) {
        String dbDriver = "COM.ibm.db2.jdbc.app.DB2Driver";
        String url = "jdbc:db2:sample";
        String user = "batra";
        String pass = "varunbatra";
        String querystring = "Select * from batra.employee";
        String fn;
        String ln;
        String bd;
        String sal;

        try {
            ConnectionProperties cp = new ConnectionProperties(dbDriver, url, user, pass);
            Query query = new Query(cp, querystring);
            QueryResults qs = query.execute();
            System.out.println("Number of rows = " + qs.size());
            while (qs.next()) {
                fn = qs.getValue("FIRSTNME");
                ln = qs.getValue("LASTNAME");
                bd = qs.getValue("BIRTHDATE");
                sal = qs.getValue("SALARY");
                System.out.println(fn + " " + ln + " birthdate " + bd + " salary " + sal);
            }
        }
        catch (Exception e) {
            //com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.webcontainer.jsp.tsx.db.Query.main2", "348");
            System.out.println("Exception: " + e.getMessage());
        }
        System.out.println("All is Fine!");
    }
1123813
@Override
    protected final T create(Object... args) {
        if (this.creating.get()) {
            throw new IllegalStateException(
                    "Singleton creator has been called again while creation is in progress, this is indicative of a creation loop in a single thread");
        }

        this.creating.set(true);
        try {
            final T instance = this.createSingleton(args);
            this.instance = instance;
            this.created.set(true);
            return instance;
        } finally {
            this.creating.set(false);
        }
    }