{@inheritDoc} Skipping creation, if the type is final or primitive.

@return the mock object or null, if the type is final or primitive.
554968
@Override
    public <T> T createMockComponent(final Class<T> type) {
        if (isFinalOrPrimitive(type)) {
            LOG.warn("Skipping creation of a mock : {} as it is final or primitive type.", type.getSimpleName());
            return null;
        }

        return Mockito.mock(type);
    }
42100
public static LazyProxyFactory createDefaultProxyFactory() {
        if (testDependencyFullFilled()) {
            final String factoryClassName = "dev.morphia.mapping.lazy.CGLibLazyProxyFactory";
            try {
                return (LazyProxyFactory) Class.forName(factoryClassName).newInstance();
            } catch (Exception e) {
                LOG.error("While instantiating " + factoryClassName, e);
            }
        }
        return null;
    }
431856
public <E> Optional<E> create(Class<E> type) {
    List<Constructor<?>> constructors = reflect().constructors()
        .filter(declared(Modifier.PUBLIC))
        .from(type);
    Optional created;
    for (Constructor<?> constructor : constructors) {
      created = tryCreate(constructor);
      if (created.isPresent()) {
        return created;
      }
    }
    return Optional.empty();
  }
278379
@Override
	public synchronized T get() {
		@Nullable T checkedObject = this.object;

		if (checkedObject == null) {
			this.object = checkedObject = Objects.requireNonNull(this.initializer.get());
		}
		return checkedObject;
	}
772545
private T createEmpty(Class<?> clazz) {
        T emptyInstance = null;

        if (clazz.isInterface()) {
            throw new IllegalArgumentException("Specified class is an interface: " + clazz.getName());
        }

        try {
            emptyInstance = (T) clazz.newInstance();
        } catch (InstantiationException ex) {
            throw new IllegalArgumentException(clazz.getName() + ". Is it an abstract class?", ex);
        } catch (IllegalAccessException ex) {
            throw new IllegalArgumentException(clazz.getName() + "Is the constructor accessible?", ex);
        }

        return emptyInstance;
    }
845867
private static Object jdk8(final Class<?> type, final Object object) {
        try {
            // a bit faster than resolving it each time
            if (jdk8OptionalFactory == null) {
                lookupOptionalFactoryMethod(type);
            }
            return jdk8OptionalFactory.invoke(null, object);
        } catch (Exception e) {
            throw new IllegalStateException("Failed to instantiate jdk Optional", e);
        }
    }
1269346
@SuppressWarnings("unchecked")
    public T get() {
        if (HystrixRequestContext.getContextForCurrentThread() == null) {
            throw new IllegalStateException(HystrixRequestContext.class.getSimpleName() + ".initializeContext() must be called at the beginning of each request before RequestVariable functionality can be used.");
        }
        ConcurrentHashMap<HystrixRequestVariableDefault<?>, LazyInitializer<?>> variableMap = HystrixRequestContext.getContextForCurrentThread().state;

        // short-circuit the synchronized path below if we already have the value in the ConcurrentHashMap
        LazyInitializer<?> v = variableMap.get(this);
        if (v != null) {
            return (T) v.get();
        }

        /*
         * Optimistically create a LazyInitializer to put into the ConcurrentHashMap.
         * 
         * The LazyInitializer will not invoke initialValue() unless the get() method is invoked
         * so we can optimistically instantiate LazyInitializer and then discard for garbage collection
         * if the putIfAbsent fails.
         * 
         * Whichever instance of LazyInitializer succeeds will then have get() invoked which will call
         * the initialValue() method once-and-only-once.
         */
        LazyInitializer<T> l = new LazyInitializer<T>(this);
        LazyInitializer<?> existing = variableMap.putIfAbsent(this, l);
        if (existing == null) {
            /*
             * We won the thread-race so can use 'l' that we just created.
             */
            return l.get();
        } else {
            /*
             * We lost the thread-race so let 'l' be garbage collected and instead return 'existing'
             */
            return (T) existing.get();
        }
    }
814283
public com.sun.javadoc.Type superclassType() {
        if (asClassDoc().isInterface()) {
            return null;
        }
        Type sup = env.types.supertype(type);
        return TypeMaker.getType(env,
                                 (sup != type) ? sup : env.syms.objectType);
    }
104805
protected Object createObject (Class type) throws InvocationTargetException {
		// Use deferred construction if a non-zero-arg constructor is available.
		DeferredConstruction deferredConstruction = Beans.getDeferredConstruction(type, config);
		if (deferredConstruction != null) return deferredConstruction;
		return Beans.createObject(type, config.privateConstructors);
	}
1158325
public T obtain () {
		T object = freeObjects.poll();
		return object != null ? object : create();
	}
955843
protected @CheckForNull T get(@Nonnull String key, boolean createIfNotExist, P createParams) throws IOException {
        while(true) {
            totalQuery.incrementAndGet();
            Object value = core.get(key);

            if(value instanceof SoftReference) {
                SoftReference<T> wfp = (SoftReference<T>) value;
                T t = wfp.get();
                if(t!=null) {
                    cacheHit.incrementAndGet();
                    return t;  // found it
                }
                weakRefLost.incrementAndGet();
            }
            if(value instanceof Loading) {
                // another thread is loading it. get the value from there.
                T t = ((Loading<T>)value).get();
                if(t!=null || !createIfNotExist)
                    return t;   // found it (t!=null) or we are just 'get' (!createIfNotExist)
            }

            // the fingerprint doesn't seem to be loaded thus far, so let's load it now.
            // the care needs to be taken that other threads might be trying to do the same.
            Loading<T> l = new Loading<>();
            if(value==null ? core.putIfAbsent(key,l)!=null : !core.replace(key,value,l)) {
                // the value has changed since then. another thread is attempting to do the same.
                // go back to square 1 and try it again.
                continue;
            }

            T t = null;
            try {
                t = load(key);
                if(t==null && createIfNotExist) {
                    t = create(key,createParams);    // create the new data
                    if(t==null)
                        throw new IllegalStateException("Bug in the derived class"); // bug in the derived classes
                }
            } catch(IOException e) {
                loadFailure.incrementAndGet();
                throw e;
            } finally {
                // let other threads know that the value is available now.
                // when the original thread failed to load, this should set it to null.
                l.set(t);
            }

            // the map needs to be updated to reflect the result of loading
            if(t!=null)
                core.put(key, new SoftReference<>(t));
            else
                core.remove(key);

            return t;
        }

    }
248488
@Override
	public T create()
	{
		try
		{
			T obj = ClassPath.newInstance(creationClass);
			
			//Copy prototype properties
			if(this.prototype != null)
				JavaBean.populate(JavaBean.toMap(prototype), obj);
			
			PropertyDescriptor pd = null;
			Class<?> clz = null;
			
			final boolean throwExceptionForMissingProperty = false;
			
			for (String property : randomizeProperties)
			{
				try
				{
					pd = JavaBean.getPropertyDescriptor(obj, property);
					clz = pd.getPropertyType();
					
					if(clz.isAssignableFrom(Class.class) || clz.isEnum())
						continue;
					
					if(clz.isAssignableFrom(String.class))
					{
						try
						{
							JavaBean.setProperty(obj, property, Text.generateId(),throwExceptionForMissingProperty);  
						}
						catch(IllegalArgumentException e)
						{
							throw new IllegalArgumentException("randomizeProperties:"+randomizeProperties+" invalid property:"+property,e);
						}
						
					}
					else if(clz.isAssignableFrom(Integer.class) || clz.isAssignableFrom(int.class) )
					{
						JavaBean.setProperty(obj, property, digits.generateInteger());
					}
					else if (clz.isAssignableFrom(long.class)  || clz.isAssignableFrom(Long.class))
					{
						JavaBean.setProperty(obj, property, digits.generateLong());
					}
					
					else if (clz.isAssignableFrom(short.class)  || clz.isAssignableFrom(Short.class))
					{
						JavaBean.setProperty(obj, property, digits.generateShort());
					}
					else if (clz.isAssignableFrom(double.class)  || clz.isAssignableFrom(Double.class))
					{
						JavaBean.setProperty(obj, property, digits.generateDouble());
					}
					else if (clz.isAssignableFrom(char.class)  || clz.isAssignableFrom(Character.class))
					{
						JavaBean.setProperty(obj, property, Text.generateId().charAt(0));
					}
					else if (clz.isAssignableFrom(float.class)  || clz.isAssignableFrom(Float.class))
					{
						JavaBean.setProperty(obj, property, digits.generateFloat());
					}
					else if (clz.isAssignableFrom(byte.class)  || clz.isAssignableFrom(Byte.class))
					{
						JavaBean.setProperty(obj, property,Byte.valueOf(Text.generateId().getBytes(IO.CHARSET)[0]));
					}
					else if (clz.isAssignableFrom(boolean.class)  || clz.isAssignableFrom(Boolean.class))
					{
						if(Calendar.getInstance().getTime().getTime()%2 ==0)
							JavaBean.setProperty(obj, property, true);
						else
							JavaBean.setProperty(obj, property, false);
					}
					else if (clz.equals(BigDecimal.class))
					{
						JavaBean.setProperty(obj, property,digits.generateBigDecimal());
					}
					else if (clz.equals(java.sql.Time.class))
					{
						JavaBean.setProperty(obj, property, 
						new java.sql.Time(
						Calendar.getInstance().getTime().getTime()));
					}
					else if (clz.equals(java.sql.Date.class))
					{
						JavaBean.setProperty(obj, property, new java.sql.Date(Calendar.getInstance().getTime().getTime()));
					}
					else if (clz.equals(java.util.Date.class))
					{
						JavaBean.setProperty(obj, property, Calendar.getInstance().getTime());
					}
					//Timestamp
					else if (clz.equals(java.sql.Timestamp.class))
					{
						JavaBean.setProperty(obj, property, new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()));
					}
					else if (clz.equals(java.util.Calendar.class))
					{
						JavaBean.setProperty(obj, property, Calendar.getInstance());
					}
					else if (clz.equals(LocalTime.class))
					{
						JavaBean.setProperty(obj, property, LocalTime.now());
					}
					else if (clz.equals(LocalDate.class))
					{
						JavaBean.setProperty(obj, property, LocalDate.now());
					}
					else if (clz.equals(LocalDateTime.class))
					{
						JavaBean.setProperty(obj, property, LocalDateTime.now());
					}
					else
					{
						JavaBean.setProperty(obj, property, ClassPath.newInstance(clz));
					}
				}
				catch (Exception e)
				{
					throw new SetupException("Cannot create property:"+property+" for object class:"
									+this.creationClass.getName()+"  ERROR:"+e.getMessage(),e); 
				}
			}
			
			return obj;
		}
		catch (RuntimeException e)
		{
			throw e;
			
		}
		catch (Exception e)
		{
			throw new RuntimeException(e.getMessage(),e);
		}
	}
324534
protected T createInstance() {
		try {
			return targetClass.newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}
248105
@Nullable
  private static ObjectType getSuperClassInstanceIfFinal(@Nullable JSType type) {
    if (type == null) {
      return null;
    }

    ObjectType obj = type.toObjectType();
    FunctionType ctor = (obj == null) ? null : obj.getSuperClassConstructor();
    JSDocInfo doc = (ctor == null) ? null : ctor.getJSDocInfo();
    if (doc != null && doc.isFinal()) {
      return ctor.getInstanceType();
    }

    return null;
  }
415990
public T create(final CreationalContext<T> creationalContext) {
        T instance = getProducer().produce(creationalContext);
        instance = checkReturnValue(instance);
        return instance;
    }
524885
protected Object convertNullValue(Class type) throws ConversionException {
        try {
            return type.isPrimitive() ? Array.get(Array.newInstance(type, 1), 0) : null;
        } catch (Exception e) {
            throw new ConversionException(String.format("Could not convert null to primitive type <%s>", type), e);
        }
    }
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());
		}
	}