javassist | Java bytecode engineering toolkit | Bytecode library

 by   jboss-javassist Java Version: rel_3_29_2_ga License: Non-SPDX

kandi X-RAY | javassist Summary

kandi X-RAY | javassist Summary

javassist is a Java library typically used in Programming Style, Bytecode applications. javassist has no bugs, it has no vulnerabilities, it has build file available and it has high support. However javassist has a Non-SPDX License. You can download it from GitHub, Maven.

Java bytecode engineering toolkit. Copyright (C) 1999-2021 by Shigeru Chiba, All rights reserved. Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation simple. It is a class library for editing bytecodes in Java; it enables Java programs to define a new class at runtime and to modify a class file when the JVM loads it. Unlike other similar bytecode editors, Javassist provides two levels of API: source level and bytecode level. If the users use the source- level API, they can edit a class file without knowledge of the specifications of the Java bytecode. The whole API is designed with only the vocabulary of the Java language. You can even specify inserted bytecode in the form of source text; Javassist compiles it on the fly. On the other hand, the bytecode-level API allows the users to directly edit a class file as other editors. This software is distributed under the Mozilla Public License Version 1.1, the GNU Lesser General Public License Version 2.1 or later, or the Apache License Version 2.0.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              javassist has a highly active ecosystem.
              It has 3849 star(s) with 682 fork(s). There are 163 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 209 open issues and 145 have been closed. On average issues are closed in 101 days. There are 7 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of javassist is rel_3_29_2_ga

            kandi-Quality Quality

              javassist has 0 bugs and 0 code smells.

            kandi-Security Security

              javassist has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              javassist code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              javassist has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              javassist releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.

            Top functions reviewed by kandi - BETA

            kandi has reviewed javassist and discovered the below as its top functions. This is intended to give you an instant insight into javassist implemented functionality, and help decide if they suit your requirements.
            • Execute the instruction at the given location in the given frame .
            • Return the string representation of the position instruction .
            • overrides the opcode in the opcode
            • Adds a multi - dimensional array to the stack .
            • Insert a gap into the code .
            • Compile a switch statement .
            • return true if a branch is found
            • Returns a string representation of an instruction .
            • Loop body of a loop .
            • Obtain a field accessor .
            Get all kandi verified functions for this library.

            javassist Key Features

            No Key Features are available at this moment for javassist.

            javassist Examples and Code Snippets

            No Code Snippets are available at this moment for javassist.

            Community Discussions

            QUESTION

            java.lang.ClassNotFoundException: org.apache.wicket.settings.def.JavaScriptLibrarySettings
            Asked 2022-Apr-14 at 18:20

            I have wicket application and it sometimes fails on :

            java.lang.NoClassDefFoundError: org/apache/wicket/settings/def/JavaScriptLibrarySettings java.base/java.lang.ClassLoader.defineClass1(Native Method) java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)

            I have this mvn configuration :

            ...

            ANSWER

            Answered 2022-Apr-14 at 18:20

            Almost all Wicket dependencies are 8.14.0 but few are 8.13.0 (not really a problem but better keep them in sync):

            • org.apache.wicket:wicket-bean-validation:jar:8.13.0:compile
            • com.googlecode.wicket-jquery-ui:wicket-jquery-ui:jar:8.13.0:compile
            • com.googlecode.wicket-jquery-ui:wicket-jquery-ui-core:jar:8.13.0:compile

            The real problem is:

            Source https://stackoverflow.com/questions/71872709

            QUESTION

            Getting warning SLF4J :Class path contains multiple SLF4J bindings
            Asked 2022-Mar-08 at 22:49

            I getting this warning while running application.

            I tried solution [here][1] but it is not working ,I am not sure what am I missing, could anyone help here? Thanks in advance.

            ...

            ANSWER

            Answered 2022-Mar-08 at 22:49

            You have to use the information SLF4J provide you and back trace the dependency using dependency:tree and its includes option.

            This message:

            Source https://stackoverflow.com/questions/71402283

            QUESTION

            How to generate looping bytecode using Javassist?
            Asked 2022-Mar-01 at 09:43

            I am trying to write a compiler for an esoteric programming language that compiles to Java Bytecode. I'm trying to use Javassist to generate the bytecode.

            I got stuck when trying to generate branching/looping code. For example, let's say I'm generating the code for:

            ...

            ANSWER

            Answered 2022-Mar-01 at 09:43

            Thanks to Holger's comment, I was able to figure out that I actually needed a StackMapTable, not a StackMap. And I indeed need a stack map table entry at every branch destination.

            Source https://stackoverflow.com/questions/71283970

            QUESTION

            Is it possible to instrument a program that also uses dynamic bytecode generation?
            Asked 2022-Feb-26 at 14:39

            I am writing a Java instrumentation program that uses the built-in Instrumentation API with Javassist (v3.26.0-GA) to intercept all the method calls in the target program. Also, I have implemented a REST API service inside this program using Java Spark to send requests for starting/stopping instrumentation by adding/removing transformers, and also for fetching intercepted methods during the instrumentation time.

            Now, while I was trying to run WebGoat (an open source Spring Boot application) with my Java agent attached from premain, I was not able to intercept all the methods successfully and in the log, there was a NotFoundException being thrown by Javassist.

            This error happened for several classes in WebGoat all had a similar common fact that they had something to do with SpringCGLIB. A few of the errors are shown below.

            ...

            ANSWER

            Answered 2022-Feb-26 at 14:39

            From previous comments:

            The unfound classes are dynamic proxies which are heavily used by the Spring Framework in order to implement AOP. Spring can use both JDK dynamic interface proxies and CGLIB proxies, the latter of which is what we are seeing here. Maybe you should simply ignore those types of classes. They are in fact created dynamically, hence the name. But they are rather a result of dynamic (sub-)class generation than of bytecode transformation.

            Yes, I have considered just ignoring those dynamically generated classes, but the whole point of my application was to capture every single method invocation as a user interacts with the web application (such as clicking on a button, etc). In this case, would it be okay to ignore these types of dynamically generated classes? I want to make sure I do not miss any method calls.

            As those classes are just dynamic proxies, they will either forward the calls to the original methods or call some AOP or interceptor logic first/instead. Either way, you would not miss anything essential, those proxies are more like switchboards or routers, the actual show happens somewhere else. I recommend you to simply try in a little playgrounds project with an aspect or two.

            You also asked how to detect and ignore dynamic proxies by their names:

            • CGLIB proxies: Spring's CGLIB proxies contain substrings like $$FastClassBySpringCGLIB$$ or $$EnhancerBySpringCGLIB$$, followed by 8 characters representing 4 hexadecimal bytes. You could either match with a regular expression of just keep it simple and match the substring BySpringCGLIB$$. If non-Spring CGLIB proxies are also in use somewhere in your application, you would have to watch for other naming patterns. But probably you would get similar errors as before when not filtering them, so you would notice automatically.

            • JDK proxies: If your Spring application also happens to use JDK proxies, you can identify them easily using JRE API call Proxy.isProxyClass(Class). Thanks to Johannes Kuhn for his comment.

            • JDK proxies (old answer): You can filter class names beginning with $Proxy, usually something like com.sun.proxy.$Proxy2 (the trailing number being different). According to the JDK documentation: "The unqualified name of a proxy class is unspecified. The space of class names that begin with the string "$Proxy" is, however, to be reserved for proxy classes." At least for Oracle and probably OpenJDK, you can match for that naming pattern. If that holds true for all JVMs, is up to you to test, if chances are that in your environments others are being used. I quickly tried with Semeru OpenJ9, and the proxy naming pattern is identical, even the package name com.sun.proxy. Pleasae note that in more recent JDK versions, JDK proxies will have fully qualified names like jdk.proxy2.$Proxy25, so in e.g. Java 16 or 17 you should not rely on package name com.sun.proxy. Either add more cases or limit matching to the leading $Proxy in the simple class name.

            Update 2022-02-26: Because there was activity on this question, I decided to add some more information about Spring-specific tools which can determine whether an object (or a class) is an AOP proxy (class) and, more specifically, if it is a CGLIB or JDK proxy:

            Take a look at tool class AopUtils and its handy methods

            • isAopProxy(Object),
            • isCglibProxy(Object),
            • isJdkDynamicProxy(Object).

            No more String matching, simply ask Spring.

            BTW, there is also a method net.sf.cglib.proxy.Proxy.isProxyClass(Class) directly in CGLIB, which is supposed to do the same, but within Spring it does not work, probably because Spring uses CGLIB in a non-canonical way. Because Spring embeds a package-relocated CGLIB in its core, the corresponding method org.springframework.cglib.proxy.Proxy.isProxyClass(Class) yields the same faulty result. So if you are working within Spring, please do not use those methods, better use AopUtils.

            Here is some example code for your convenience, showing how to determine Spring AOP proxy types (JDK vs. CGLIB proxies) using AopUtils. See also my answer here for how to configure Spring in order to use both proxy types.

            BTW, instead of Javassist you could also use AspectJ for your purpose. It sounds like a pretty typical use case.

            Source https://stackoverflow.com/questions/70468909

            QUESTION

            Spring Boot Logging to a File
            Asked 2022-Feb-16 at 14:49

            In my application config i have defined the following properties:

            ...

            ANSWER

            Answered 2022-Feb-16 at 13:12

            Acording to this answer: https://stackoverflow.com/a/51236918/16651073 tomcat falls back to default logging if it can resolve the location

            Can you try to save the properties without the spaces.

            Like this: logging.file.name=application.logs

            Source https://stackoverflow.com/questions/71142413

            QUESTION

            Javassist Classpool.get() does not find class when using fully qualified name
            Asked 2022-Feb-05 at 01:17

            I am attempting to get a simple Javassist example going. Consider the following code. Assume variable classPath points to a correct class folder that contains the required .class file.

            When running, the first invocation of classPool.get() succeeds and the second fails. The spec of method ClassPool.get() requires a fully-qualified class name. Why is that?

            ...

            ANSWER

            Answered 2022-Feb-05 at 01:17

            You simply need to use the correct classpath. This is wrong, because you are pointing into a package subdirectory rather than straight to the root:

            Source https://stackoverflow.com/questions/70992972

            QUESTION

            Cannot execute any Mockito test. With JDK17 gives "NoSuchMethodException: sun.misc.Unsafe.defineClass(...) "
            Asked 2021-Dec-20 at 13:30

            When upgrading my app from Spring Boot 2.2 with JDK 11 to Spring Boot 2.5.5 with JDK 17, Mockito gives this error:

            ...

            ANSWER

            Answered 2021-Dec-20 at 13:30

            It was an Intelli-J issue!

            So, cleaning the Intelli-J dependency spaghetti up solved it!

            1. File > Invalidate cache ... and restart. Helped a bit.
            2. Closing the Intelli-J project. Then removed manually the ".idea" folder and any *.iml file.

            Yes, I did option 1 previously. Especially doing action 2 solved it within a minute.

            Source https://stackoverflow.com/questions/70395010

            QUESTION

            Replicate resource warnings
            Asked 2021-Dec-20 at 10:13

            How can I resolved these warnings during web application loading:

            ...

            ANSWER

            Answered 2021-Dec-20 at 08:28

            These messages usually mean that your application is importing multiple versions of the same files, or that each of these files in imported multiple times. From the message in this case, it looks like you have identical files located in the same place or being overwritten by the same files.

            In which context do you see these files? (IDE, building, running server, etc) If you see these in your IDE (Eclipse?), you may have a project configuration issue, such as importing the same library folder twice through different path.

            Additionally, the zkbind dependency will itself transitively load other ZK dependencies. I'd recommend running a mvn clean dependency:tree command locally to see which dependencies are being added to your application, and from which parent.

            Source https://stackoverflow.com/questions/70415779

            QUESTION

            Replacing / Swapping a Java class in Java agent instrumentation
            Asked 2021-Dec-17 at 17:16

            I've read this post which does the bytecode instrumentation in a "line by line" approach. It's clumsy and bug-prone. I wonder if Javassit supports "replacing" or "swapping" a class with an instrumented class. I see the redefineClasses method but I'm not sure it's used for that purposes, plus I can't find any examples around that.

            I appreciate if anyone in SO can give me an example on using redefineClasses in Javassist

            My goal is to use Java instrumentation to extract some meaningful data inside multiple Java classes and methods, much more than just printing start/end time in those examples. That's why I think "swapping a Java class" approach is more efficient during development.

            What do you guys think and recommend? Thank you.

            ...

            ANSWER

            Answered 2021-Dec-17 at 17:16

            Questions not presenting any of your own code but asking others for complete sample code or other resources are likely to be closed as off-topic. At the time of writing this, your question already attracted 2 of 3 necessary close votes. Please remember what I told you in your other question about how to ask good questions and how an MCVE helps you do that.

            Because you are new to Java instrumentation, I want to elaborate a little more on Johannes' correct comments: I recommend you to not just read the Baeldung article but also some related javadocs.

            For example, the Java 8 API documentation for Instrumentation.redefineClasses clearly states the limitations when redefining classes:

            The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance. These restrictions maybe be lifted in future versions.

            Alas, the restrictions have not been lifted as of Java 17. The same method is described there as follows:

            The supported class file changes are described in JVM TI RedefineClasses.

            The document pointed to basically says the same as the Java 8 documentation, only in some more detail:

            The redefinition may change method bodies, the constant pool and attributes (unless explicitly prohibited). The redefinition must not add, remove or rename fields or methods, change the signatures of methods, change modifiers, or change inheritance. The redefinition must not change the NestHost, NestMembers, Record, or PermittedSubclasses attributes. These restrictions may be lifted in future versions.

            Besides, the very same restrictions apply to Instrumentation.retransformClasses, the difference basically being that you do not start from scratch there but use existing class bytes as an input and can chain multiple transformers in order to incrementally instrument your existing class. But even with redefinition, the base line stays the original class, if it was loaded before.

            Source https://stackoverflow.com/questions/70384228

            QUESTION

            java.lang.NullPointerException: Cannot invoke "java.lang.reflect.AccessibleObject.setAccessible(boolean)" because "ao" is null
            Asked 2021-Dec-06 at 20:33

            I am doing Dynamic Web Project using JPA in Java 17. I have a class called UserEntity. In the first page I have a register button, which has the following functionality:

            ...

            ANSWER

            Answered 2021-Dec-06 at 20:26

            As far as I know there are multiple things that can cause this

            • Your Java POJO Mapping class may not have the empty/default constructor
            • Any collections you have should have the default constructor or overridden hashcode and equals method. That is, the same rules apply for any joined collections/parent-children.

            If you have your constructors right for POJO classes than check hibernate.properties file and try changing

            Source https://stackoverflow.com/questions/70251381

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install javassist

            You can download it from GitHub, Maven.
            You can use javassist like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the javassist component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link