jbossas / jboss-classfilewriter Goto Github PK
View Code? Open in Web Editor NEWJBoss Class File Writer
License: Apache License 2.0
JBoss Class File Writer
License: Apache License 2.0
Is there a reason to limit the size of a constant pool to short
, i.e. 32767? According to JVM the constant pool is limited to 65535 entries. See also http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.11.
May I get source code on classwriter?
For example of HttpRequestParser(Undertow) ..its generated to HttpRequestParser$$generated.class(using org.jboss.classfilewriter)
I was researching how Undertow working /Get dependences/Up on IDE(JDeveloper) ,
wanted trace (debug )way request /response, but discovered what way go out in HttpRequestParser$$generayed.class.
This one is a generated tricky, complicate process, of «parser-generator»(io.undertow.annotationprocessor use
org.jboss.classfilewriter
https://github.com/undertow-io/undertow/tree/master/parser-generator/src/main/java/io/undertow/annotationprocessor
)
and I did not found
HttpRequestParser$$generayed.java in annotation-source target.
I was writed
com.sun.tools.javac.Main.main (new String[] {"-proc:only", "-processor", "io.undertow.annotationprocessor.HttpParserAnnotationProcessor", "HttpRequestParser.java"});
Append code to HttpParserAnnotationProcessor(process)
JavaFileObject jfo = filer.createSourceFile(classElement.getQualifiedName() + "Info");
But I get only class file and empty source file;
How I can get source code for annotation? May I modyfy code to get source?(or jboss-classfilefriter working only class files?)
(On undertow within portal does not exist issue
Writed on https://issues.redhat.com/projects/UNDERTOW
No answer.
)
Java 11 has deleted the Unsafe.defineClass method. Instead of using this method, we could use an alternative strategy:
ClassLoader.defineClass
(maybe using Unsafe to toggle the accessibility flag)org.jboss.modules.ClassDefiner
to define generated classesWeld depends on jboss-classfilewriter. Since Weld is also used in OSGi enrivonment we have to embed jboss-classfilewriter in Weld's OSGi bundle. It would be cleaner if jboss-classfilewriter itself could be used as an OSGi bundle.
Hi
Not available LICENSE file in source directory structure
Please. Added license and copyright notice.
the fedora pakaging guideline is very strictly precise about this problem
https://fedoraproject.org/wiki/Packaging:LicensingGuidelines?rd=Packaging/LicensingGuidelines#License_Text
Thanks in advance
Regards
Caused By: java.lang.NoSuchFieldException: override
at java.base/java.lang.Class.getDeclaredField(Class.java:2412)
at org.jboss.classfilewriter.ClassFile$1.run(ClassFile.java:392)
at org.jboss.classfilewriter.ClassFile$1.run(ClassFile.java:385)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.jboss.classfilewriter.ClassFile.(ClassFile.java:385)
Truncated. see log file for complete stacktrace
Currently it's always marked as invalid and apparently ignored when CodeAttribute
is written.
This is likely the cause (or one of the causes) of WELD-2093.
Reproducer - a simple example (created during weld knowledge share):
https://github.com/mkouba/bytecode-basics/blob/master/src/main/java/learn/bytecode/Main.java#L93-L101
If you run the Main, you'll get the "java.lang.VerifyError: Expecting a stackmap frame at branch target". I'm not sure it's caused solely by the absence of StackMapTable. But the truth is it might be problem with future versions of JVM (even now it seems the JVMs are not required to fallback to verification by type inference for 50.0).
Right now you have to use different constructs for forward versus backward branches. It's easy enough to write a marker class which automatically backfills branches, but putting this in the main API would be a nice feature. Also something that is not really possible is to combine multiple such markers - to do so would require BranchEnds to be filled by a CodeLocation (right now they can only be added as a mark into the CodeAttribute's current position).
Eg. this #28 could have a good first issue label added
See this old post why this is a good idea: https://dzone.com/articles/automatic-module-name-calling-all-java-library-maintainers
TLDR:
It costs nothing, has no compatibility issues and improves the usability of the library for JPMS enabled projects.
All that is needed is a single line in the MANIFEST.MF:
Automatic-Module-Name: org.jboss.classfilewriter
generic field support is important imho, w/o it, we need to do lots of extra work to use the generated class
for example, i'm trying to use classwriter to generate class for hibernate testing, and the jpa collection annotation requires generic type to dertimine the underlying collection element type, or i have to set targetClass property for ElementCollection annotations.
thanks
Since build OpenJDK Runtime Environment (build 17-ea+21-1866)
weld fails to start due to issue in EnumAnnotationValue
.
This issue was fixed in PR #15, though it was never merged.
How to reproduce (with Weld):
How to reproduce in general:
ClassFile
from a class with an enum annotation valuegetAnnotations()
on the loaded classStack trace (from Weld):
Exception in thread "main" java.lang.reflect.GenericSignatureFormatError: Signature Parse error: Expected Field Type Signature
Remaining input: org.eclipse.microprofile.openapi.annotations.enums.SchemaType
at java.base/sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:124)
at java.base/sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:291)
at java.base/sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:277)
at java.base/sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java:469)
at java.base/sun.reflect.generics.parser.SignatureParser.parseTypeSig(SignatureParser.java:188)
at java.base/sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:430)
at java.base/sun.reflect.annotation.AnnotationParser.parseEnumValue(AnnotationParser.java:468)
at java.base/sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:343)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:282)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:227)
at java.base/sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:348)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:282)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:227)
at java.base/sun.reflect.annotation.AnnotationParser.lambda$parseAnnotationArray$2(AnnotationParser.java:726)
at java.base/sun.reflect.annotation.AnnotationParser.parseArrayElements(AnnotationParser.java:737)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotationArray(AnnotationParser.java:725)
at java.base/sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:528)
at java.base/sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:351)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:282)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:121)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:73)
at java.base/java.lang.reflect.Executable.declaredAnnotations(Executable.java:624)
at java.base/java.lang.reflect.Executable.declaredAnnotations(Executable.java:622)
at java.base/java.lang.reflect.Executable.getDeclaredAnnotations(Executable.java:610)
at java.base/java.lang.reflect.Method.getDeclaredAnnotations(Method.java:747)
at java.base/java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:566)
at org.jboss.weld.resources.HotspotReflectionCache.internalGetAnnotations(HotspotReflectionCache.java:58)
at org.jboss.weld.resources.DefaultReflectionCache.lambda$new$0(DefaultReflectionCache.java:40)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.lambda$new$0(ReentrantMapBackedComputingCache.java:55)
at org.jboss.weld.util.LazyValueHolder$1.computeValue(LazyValueHolder.java:32)
at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:46)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:72)
at org.jboss.weld.resources.DefaultReflectionCache.getAnnotations(DefaultReflectionCache.java:75)
at org.jboss.weld.annotated.slim.backed.BackedAnnotated.getAnnotations(BackedAnnotated.java:36)
at org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedMethodImpl.of(EnhancedAnnotatedMethodImpl.java:61)
at org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedTypeImpl.<init>(EnhancedAnnotatedTypeImpl.java:224)
at org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedTypeImpl.of(EnhancedAnnotatedTypeImpl.java:134)
at org.jboss.weld.resources.ClassTransformer$TransformSlimAnnotatedTypeToEnhancedAnnotatedType.apply(ClassTransformer.java:93)
at org.jboss.weld.resources.ClassTransformer$TransformSlimAnnotatedTypeToEnhancedAnnotatedType.apply(ClassTransformer.java:90)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.lambda$new$0(ReentrantMapBackedComputingCache.java:55)
at org.jboss.weld.util.LazyValueHolder$1.computeValue(LazyValueHolder.java:32)
at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:46)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:72)
at org.jboss.weld.resources.ClassTransformer.getEnhancedAnnotatedType(ClassTransformer.java:251)
at org.jboss.weld.resources.ClassTransformer.getEnhancedAnnotatedType(ClassTransformer.java:232)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.initEnhancedSubclass(SubclassedComponentInstantiator.java:86)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.<init>(SubclassedComponentInstantiator.java:79)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.forInterceptedDecoratedBean(SubclassedComponentInstantiator.java:63)
at org.jboss.weld.injection.producer.BeanInjectionTarget.initializeAfterBeanDiscovery(BeanInjectionTarget.java:121)
at org.jboss.weld.injection.producer.InjectionTargetInitializationContext.initialize(InjectionTargetInitializationContext.java:42)
at org.jboss.weld.injection.producer.InjectionTargetService.initialize(InjectionTargetService.java:63)
at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:481)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:86)
jboss-classfilewriter 1.3.0.Final available at Maven Central has this OSGi META-INF/MANIFEST.MF
header:
Require-Capability: osgi.ee;filter:="(osgi.ee=UNKNOWN)"
maven-bundle-plugin 3.3.0 is quite old and didn't know much about JDK11.
It's enough to change the version of the plugin.
Hi Stuart, I think you forgot to check-in StringValuedAnnotation.java
file. Tests for 1.0.1.Final
fail because of this:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project jboss-classfilewriter: Compilation failure: Compilation failure: [ERROR] bootstrap class path not set in conjunction with -source 1.6 [ERROR] /home/goldmann/fedora/jboss-classfilewriter/BUILD/jboss-classfilewriter-1.0.1.Final/src/test/java/org/jboss/classfilewriter/test/annotation/MethodAnnotationClass.java:[56,30] error: cannot find symbol [ERROR] class MethodAnnotationClass [ERROR] /home/goldmann/fedora/jboss-classfilewriter/BUILD/jboss-classfilewriter-1.0.1.Final/src/test/java/org/jboss/classfilewriter/test/annotation/MethodAnnotationClass.java:[55,5] error: cannot find symbol [ERROR] class MethodAnnotationClass [ERROR] /home/goldmann/fedora/jboss-classfilewriter/BUILD/jboss-classfilewriter-1.0.1.Final/src/test/java/org/jboss/classfilewriter/test/annotation/MethodAnnotationTest.java:[44,40] error: cannot find symbol [ERROR] class MethodAnnotationTest [ERROR] /home/goldmann/fedora/jboss-classfilewriter/BUILD/jboss-classfilewriter-1.0.1.Final/src/test/java/org/jboss/classfilewriter/test/annotation/MethodAnnotationTest.java:[46,40] error: cannot find symbol [ERROR] -> [Help 1]
When running with Jigsaw b162 or later with --permit-illegal-access, the following warnings are generated.
This is due to use of setAccessible to break into JDK classes.
WARNING: Illegal access by org.jboss.classfilewriter.ClassFile$1 (file:/modules/org.jboss.classfilewriter.jboss-classfilewriter.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Illegal access by org.jboss.classfilewriter.ClassFile$1 (file:/modules/org.jboss.classfilewriter.jboss-classfilewriter.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
How to fix this issue?
DuplicateMemberException Method already exists
Stacktrace:
org.jboss.classfilewriter.ClassFile.addMethod(ClassFile.java:180)
org.jboss.classfilewriter.ClassFile.addMethod(ClassFile.java:195)
org.jboss.weld.bean.proxy.ProxyFactory.addMethodsFromClass(ProxyFactory.java:611)
org.jboss.weld.bean.proxy.ProxyFactory.addMethods(ProxyFactory.java:564)
org.jboss.weld.bean.proxy.ClientProxyFactory.addMethods(ClientProxyFactory.java:113)
org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:457)
org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:370)
org.jboss.weld.bean.proxy.ProxyFactory.run(ProxyFactory.java:331)
org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:323)
org.jboss.weld.bean.proxy.ClientProxyFactory.create(ClientProxyFactory.java:83)
org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:205)
org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:195)
org.jboss.weld.bean.proxy.ClientProxyProvider.access$
org.jboss.weld.bean.proxy.ClientProxyProvider$CreateClientProxy.apply(ClientProxyProvider.java:52)
org.jboss.weld.bean.proxy.ClientProxyProvider$CreateClientProxy.apply(ClientProxyProvider.java:48)
org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.lambda$
org.jboss.weld.util.cache.ReentrantMapBackedComputingCache$$Lambda$.get
org.jboss.weld.util.LazyValueHolder$1.computeValue(LazyValueHolder.java:32)
org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:46)
org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:72)
org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getCastValue(ReentrantMapBackedComputingCache.java:78)
org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:229)
org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:688)
org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
org.jboss.weld.util.Beans.injectBoundFields(Beans.java:336)
org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:347)
org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:69)
com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl$3.run(WebSphereInjectionServicesImpl.java:323)
com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl$3.run(WebSphereInjectionServicesImpl.java:320)
java.security.AccessController.doPrivileged(AccessController.java:678)
com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.aroundInject(WebSphereInjectionServicesImpl.java:320)
org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71)
org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117)
org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)
org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)
org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694)
org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.