we have to use reflection for this since Spring is not a mandatory dependency / not necessarily on the classpath for chorus core
14999
private String findSpringContextFileName(Object handler, Annotation[] annotations) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        String contextFileName = null;
        for (Annotation a : annotations) {
            String n = a.annotationType().getSimpleName();
            if ( n.equals("ContextConfiguration") || n.equals("SpringContext")) {
                log.trace("Found an spring context annotation " + a);
                contextFileName = getContextPathFromSpringAnnotation(handler, a, n);
                if ( contextFileName != null) {
                    break;
                }
            }
        }
        return contextFileName;
    }
82606
static <T> MaybeObserver<T> wrap(MaybeObserver<T> downstream,
                                     List<RunnableInstrumenter> instrumentations) {
        return new RxInstrumentedMaybeObserver<>(downstream, instrumentations);
    }
1253105
private StringBuffer loadScriptTemplate(String path) {
		StringWriter sw = new StringWriter();

		InputStream is = null;
		try {
			is = ClassLoaderResourceUtils.getResourceAsStream(path, this);
			int i;
			while ((i = is.read()) != -1) {
				sw.write(i);
			}

		} catch (IOException e) {
			Marker fatal = MarkerFactory.getMarker("FATAL");
			LOGGER.error(fatal, "a serious error occurred when initializing ClientSideHandlerGeneratorImpl");
			throw new BundlingProcessException("Classloading issues prevent loading the loader template to be loaded. ",
					e);
		} finally {
			IOUtils.close(is);
		}

		return sw.getBuffer();
	}
864269
private void registerServiceProxy(DefaultListableBeanFactory defaultListableBeanFactory, String servicePath, String serviceBeanName) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(JsonServiceExporter.class).addPropertyReference("service", serviceBeanName);
		BeanDefinition serviceBeanDefinition = findBeanDefinition(defaultListableBeanFactory, serviceBeanName);
		for (Class<?> currentInterface : getBeanInterfaces(serviceBeanDefinition, defaultListableBeanFactory.getBeanClassLoader())) {
			if (currentInterface.isAnnotationPresent(JsonRpcService.class)) {
				String serviceInterface = currentInterface.getName();
				logger.debug("Registering interface '{}' for JSON-RPC bean [{}].", serviceInterface, serviceBeanName);
				builder.addPropertyValue("serviceInterface", serviceInterface);
				break;
			}
		}
		if (objectMapper != null) {
			builder.addPropertyValue("objectMapper", objectMapper);
		}

		if (errorResolver != null) {
			builder.addPropertyValue("errorResolver", errorResolver);
		}

		if (invocationListener != null) {
			builder.addPropertyValue("invocationListener", invocationListener);
		}

		if (registerTraceInterceptor != null) {
			builder.addPropertyValue("registerTraceInterceptor", registerTraceInterceptor);
		}

		if (httpStatusCodeProvider != null) {
			builder.addPropertyValue("httpStatusCodeProvider", httpStatusCodeProvider);
		}

		if (convertedParameterTransformer != null) {
			builder.addPropertyValue("convertedParameterTransformer", convertedParameterTransformer);
		}

		builder.addPropertyValue("backwardsCompatible", backwardsCompatible);
		builder.addPropertyValue("rethrowExceptions", rethrowExceptions);
		builder.addPropertyValue("allowExtraParams", allowExtraParams);
		builder.addPropertyValue("allowLessParams", allowLessParams);

		defaultListableBeanFactory.registerBeanDefinition(servicePath, builder.getBeanDefinition());
	}
682146
@SuppressWarnings("unchecked")
    public <U extends BeanPath<? extends T>> U as(Class<U> clazz) {
        try {
            if (!casts.containsKey(clazz)) {
                PathMetadata metadata;
                if (pathMixin.getMetadata().getPathType() != PathType.COLLECTION_ANY) {
                    metadata = PathMetadataFactory.forDelegate(pathMixin);
                } else {
                    metadata = pathMixin.getMetadata();
                }
                U rv;
                // the inits for the subtype will be wider, if it's a variable path
                if (inits != null && pathMixin.getMetadata().getPathType() != PathType.VARIABLE) {
                    rv = clazz.getConstructor(PathMetadata.class, PathInits.class).newInstance(metadata, inits);
                } else {
                    rv = clazz.getConstructor(PathMetadata.class).newInstance(metadata);
                }
                casts.put(clazz, rv);
                return rv;
            } else {
                return (U) casts.get(clazz);
            }

        } catch (InstantiationException e) {
            throw new ExpressionException(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new ExpressionException(e.getMessage(), e);
        } catch (InvocationTargetException e) {
            throw new ExpressionException(e.getMessage(), e);
        } catch (NoSuchMethodException e) {
            throw new ExpressionException(e.getMessage(), e);
        }
    }
918950
@Override
	public void setCustomPostprocessors(Map<String, String> keysClassNames) {
		for (Entry<String, String> entry : keysClassNames.entrySet()) {
			ResourceBundlePostProcessor customProcessor = (ResourceBundlePostProcessor) ClassLoaderResourceUtils
					.buildObjectInstance((String) entry.getValue());
			boolean isVariantPostProcessor = customProcessor.getClass()
					.getAnnotation(VariantPostProcessor.class) != null;

			if (customProcessor instanceof BundlingProcessLifeCycleListener) {
				listeners.add((BundlingProcessLifeCycleListener) customProcessor);
			}
			String key = (String) entry.getKey();
			customPostProcessors.put(key, getCustomProcessorWrapper(customProcessor, key, isVariantPostProcessor));
		}
	}
96448
@Bean
	public SpringDataSourceBeanPostProcessor monitoringDataSourceBeanPostProcessor(
			@Value("${javamelody.excluded-datasources:}") String excludedDatasources) {
		// IMPORTANT: We cannot inject JavaMelodyConfigurationProperties here because of bean load order! Therefore we have
		// to use that rather dirty way to inject the configuration value.
		final SpringDataSourceBeanPostProcessor processor = new SpringDataSourceBeanPostProcessor();
		if (excludedDatasources != null && excludedDatasources.trim().length() > 0) {
			processor.setExcludedDatasources(
					new HashSet<>(Arrays.asList(excludedDatasources.split(","))));
		}
		return processor;
	}
826330
private static MethodHandle unmapJava7Or8(MethodHandles.Lookup lookup) throws ReflectiveOperationException
  {
    // "Compile" a MethodHandle that is roughly equivalent to the following lambda:
    //
    // (ByteBuffer buffer) -> {
    //   sun.misc.Cleaner cleaner = ((java.nio.DirectByteBuffer) byteBuffer).cleaner();
    //   if (nonNull(cleaner))
    //     cleaner.clean();
    //   else
    //     noop(cleaner); // the noop is needed because MethodHandles#guardWithTest always needs both if and else
    // }
    //
    Class<?> directBufferClass = Class.forName("java.nio.DirectByteBuffer");
    Method m = directBufferClass.getMethod("cleaner");
    m.setAccessible(true);
    MethodHandle directBufferCleanerMethod = lookup.unreflect(m);
    Class<?> cleanerClass = directBufferCleanerMethod.type().returnType();
    MethodHandle cleanMethod = lookup.findVirtual(cleanerClass, "clean", MethodType.methodType(void.class));
    MethodHandle nonNullTest = lookup.findStatic(Objects.class, "nonNull",
                                                 MethodType.methodType(boolean.class, Object.class)
    ).asType(MethodType.methodType(boolean.class, cleanerClass));
    MethodHandle noop = MethodHandles.dropArguments(MethodHandles.constant(
        Void.class,
        null
    ).asType(MethodType.methodType(void.class)), 0, cleanerClass);
    MethodHandle unmapper = MethodHandles.filterReturnValue(
        directBufferCleanerMethod,
        MethodHandles.guardWithTest(nonNullTest, cleanMethod, noop)
    ).asType(MethodType.methodType(void.class, ByteBuffer.class));
    return unmapper;
  }
501217
private void preRegisterMBeanServerPipelineService(final BundleContext systemContext) {
        PlatformMBeanServerBuilder.addPlatformMBeanServerBuilderListener(new PlatformMBeanServerBuilderListener() {
            @Override
            @FFDCIgnore(IllegalStateException.class)
            public void platformMBeanServerCreated(final MBeanServerPipeline pipeline) {
                if (pipeline != null) {
                    final Hashtable<String, String> svcProps = new Hashtable<String, String>();
                    try {
                        AccessController.doPrivileged(new PrivilegedAction<Void>() {
                            @Override
                            public Void run() {
                                systemContext.registerService(MBeanServerPipeline.class.getName(), pipeline, svcProps);
                                return null;
                            }
                        });
                    } catch (IllegalStateException ise) { /* This instance of the system bundle is no longer valid. Ignore it. */
                    }
                }
            }
        });
    }
729645
@Override
    public Resource createRelative(String relativePath) {
        String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
        return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
    }
5981
@Nullable
  private static <T> TreePath findEnclosingMethodOrLambdaOrInitializer(TreePath path) {
    while (path != null) {
      if (path.getLeaf() instanceof MethodTree) {
        return path;
      }
      TreePath parent = path.getParentPath();
      if (parent != null) {
        if (parent.getLeaf() instanceof ClassTree) {
          if (path.getLeaf() instanceof BlockTree) {
            // this is a class or instance initializer block
            return path;
          }
          if (path.getLeaf() instanceof VariableTree
              && ((VariableTree) path.getLeaf()).getInitializer() != null) {
            // this is a field with an inline initializer
            return path;
          }
        }
        if (parent.getLeaf() instanceof LambdaExpressionTree) {
          return parent;
        }
      }
      path = parent;
    }
    return null;
  }
441075
private Type enterSyntheticAnnotation(String name) {
        // for now, leave the module null, to prevent problems from synthesizing the
        // existence of a class in any specific module, including noModule
        ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type;
        ClassSymbol sym = (ClassSymbol)type.tsym;
        sym.completer = Completer.NULL_COMPLETER;
        sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
        sym.erasure_field = type;
        sym.members_field = WriteableScope.create(sym);
        type.typarams_field = List.nil();
        type.allparams_field = List.nil();
        type.supertype_field = annotationType;
        type.interfaces_field = List.nil();
        return type;
    }
529527
public static void wireInSpring(Object o, String myBeanName) {
        // Lambda does not do this for you - though serverless does have a library to do it
        if (ctx == null) {
            synchronized (lck) {
                if (ctx == null) {
                    LOG.info("LamdaSpringUtil CTX is null -  initialising spring");
                    ctx = new ClassPathXmlApplicationContext(globalRootContextPath);
                }
            }
        } else {
            LOG.debug("LamdaSpringUtil CTX is not null - not initialising spring");
        }
        AutowireCapableBeanFactory factory = ctx.getAutowireCapableBeanFactory();
        factory.autowireBean(o);
        factory.initializeBean(0, myBeanName);
    }
742439
@SuppressWarnings("unchecked")
    private <T> TypedStringConverter<T> findAnyConverter(final Class<T> cls) {
        // check factories
        for (StringConverterFactory factory : factories) {
            StringConverter<T> factoryConv = (StringConverter<T>) factory.findConverter(cls);
            if (factoryConv != null) {
                return TypedAdapter.adapt(cls, factoryConv);
            }
        }
        return null;
    }
147187
public static void main(String[] args) throws RunnerException {
        new Runner(new OptionsBuilder()
                .include(WILDCARD + SuperClassInvocationBenchmark.class.getSimpleName() + WILDCARD)
                .include(WILDCARD + StubInvocationBenchmark.class.getSimpleName() + WILDCARD)
                .include(WILDCARD + ClassByImplementationBenchmark.class.getSimpleName() + WILDCARD)
                .include(WILDCARD + ClassByExtensionBenchmark.class.getSimpleName() + WILDCARD)
                .include(WILDCARD + TrivialClassCreationBenchmark.class.getSimpleName() + WILDCARD)
                .forks(0) // Should rather be 1 but there seems to be a bug in JMH.
                .build()).run();
    }
825135
private static void buildSwagger(String basePath) {
        // This configures Swagger
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.0");
        beanConfig.setResourcePackage(QueryResource.class.getPackage().getName());
        beanConfig.setBasePath(basePath);
        beanConfig.setDescription("Embedded Druid");
        beanConfig.setTitle("Embedded Druid");
        beanConfig.setScan(true);
    }
947241
protected void bindToSpringApplication(ConfigurableEnvironment environment) {
		try {
			Binder.get(environment).bind("spring.main", Bindable.ofInstance(this));
		}
		catch (Exception ex) {
			throw new IllegalStateException("Cannot bind to SpringApplication", ex);
		}
	}