2017-07-12 63 views
1

我試圖使用ByteBuddy的具體類動態定義sublclass如下反思錯誤時創建的谷歌應用程序使用ByteBuddy引擎

Class<? extends MyConcreteClass> dynamicType = new ByteBuddy() 
    .subclass(MyConcreteClass.class, ConstructorStrategy.Default.DEFAULT_CONSTRUCTOR) 
    .name(dynamicClassName) 
    .annotateType(MyConcreteClass.class.getDeclaredAnnotations()) 
    .make() 
    .load(MyConcreteClass.class.getClassLoader()) 
    .getLoaded(); 

此代碼從JUnit測試中工作的一類,但是當我在Google App Engine下運行它,我會得到以下例外。

java.lang.IllegalStateException: Cannot access java.lang.reflect.Parameter#getModifiers 
at net.bytebuddy.description.method.ParameterList$ForLoadedExecutable$Dispatcher$ForJava8CapableVm.getParameterCount(ParameterList.java:261) 
at net.bytebuddy.description.method.ParameterList$ForLoadedExecutable.size(ParameterList.java:157) 
at net.bytebuddy.description.method.ParameterList$TypeSubstituting.size(ParameterList.java:582) 
at net.bytebuddy.matcher.CollectionSizeMatcher.matches(CollectionSizeMatcher.java:34) 
at net.bytebuddy.matcher.CollectionSizeMatcher.matches(CollectionSizeMatcher.java:13) 
at net.bytebuddy.matcher.MethodParametersMatcher.matches(MethodParametersMatcher.java:32) 
at net.bytebuddy.matcher.MethodParametersMatcher.matches(MethodParametersMatcher.java:13) 
at net.bytebuddy.matcher.ElementMatcher$Junction$Conjunction.matches(ElementMatcher.java:101) 
at net.bytebuddy.matcher.ElementMatcher$Junction$Conjunction.matches(ElementMatcher.java:101) 
at net.bytebuddy.matcher.FilterableList$AbstractBase.filter(FilterableList.java:96) 
at net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy$Default$2.doExtractConstructors(ConstructorStrategy.java:82) 
at net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy$Default.extractConstructors(ConstructorStrategy.java:176) 
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.applyConstructorStrategy(SubclassDynamicTypeBuilder.java:185) 
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:162) 
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:155) 
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:2559) 
... 
Caused by: java.lang.IllegalAccessException: Reflection is not allowed on public int java.lang.reflect.Executable.getParameterCount() 
at com.google.appengine.tools.development.agent.runtime.Runtime.verifyWhiteListed(Runtime.java:90) 
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:125) 
at net.bytebuddy.description.method.ParameterList$ForLoadedExecutable$Dispatcher$ForJava8CapableVm.getParameterCount(ParameterList.java:259) 

執行方法make()時拋出異常。

有沒有辦法在GAE下進行這項工作?

回答

2

這是一個非常隨機的限制,絕對是GAE上的一個bug。請報告。

作爲背景:Byte Buddy檢測JVM的版本並提供相應的功能。在這種情況下,它檢測到隨Java 8添加的參數API存在並使用它。但是,GAE似乎不允許通過反射來使用它。

相關問題