Application program hot repair method, system, device and readable storage medium
By loading and registering the class files of the target application subclass through the class loader, the framework complexity problem caused by the unimplemented declared interface in the online bug repair is solved, and efficient and stable repair of the application is achieved.
Patent Information
- Application Number
- CN202210934739.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-04
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2042-08-04
AI Technical Summary
Existing online bug repair technology cannot effectively repair bugs when the class to be repaired does not implement a certain declared interface, resulting in high complexity in reference processing in the framework.
The class file of the target application subclass is loaded through the class loader and registered as the object of the class identifier corresponding to the application to be repaired. The class to be repaired is used as a bridge to implement the call of the repair logic or method, avoiding the scenario of unimplemented declared interface.
It reduces the complexity of reference processing in the framework, enables efficient repair of applications without stopping services, and reduces the complexity of calling repair methods.
Smart Images

Figure CN115291923B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, system, device, and readable storage medium for hot repairing an application. Background Art
[0002] Resolving online issues (bugs) in production environments has always been a headache for system developers and operators. Some industries, such as finance and gaming, are very application-sensitive. Services may not be discontinued for a month or longer, or versions may not be re-released due to regulatory requirements. However, no one can guarantee that online logic is 100% problem-free. This necessitates online bug fixes without stopping services to ensure continuity and stability.
[0003] There are two main technical approaches for online bug repair in the industry. One is to use JavaAgent technology (a technology that depends on Java applications and can make relevant changes to their bytecode) and leverage the instrument tool's API interfaces to directly reload the class to be repaired at runtime. The disadvantage of this method is that it cannot add a dependent class that did not originally exist. The number of implemented interfaces, interface types, method accessors, number of fields, and method signatures of the repair class and the class to be repaired must be exactly the same. The other is to reload the repair class of the original class. The disadvantage of this method is that the class to be repaired and the repair class must be implementation classes of the same declared interface. Otherwise, after the repair class is reloaded, its original type cannot accept the newly loaded repair class because the JVM (Java Virtual Machine) will no longer consider it the same class before and after the repair. Therefore, re-calling the repair method requires the combination of reflection and other methods, which increases the complexity of implementation in various frameworks. In addition, the situation where the class to be repaired does not implement a declared interface is relatively common in existing engineering code. Summary of the Invention
[0004] The main technical problem solved by this application is to provide a hot repair method, system, device and readable storage medium for an application, which can avoid the scenario where the class to be repaired does not implement a certain declared interface, and reduce the complexity of reference processing in various frameworks caused by subsequent calls to repair logic or methods.
[0005] In order to solve the above problems, the first aspect of the present application provides a hot repair method for an application, which includes: a terminal obtains a patch package of the application to be repaired, and the patch package includes a class file of a target application subclass corresponding to the application to be repaired; a class loader is used to load the class file of the target application subclass; and the target application subclass is registered as an object corresponding to a class identifier corresponding to the application to be repaired.
[0006] The step of loading the class file of the target application subclass by using a class loader includes: loading the class file of the target application subclass into a JVM by using the class loader.
[0007] Among them, registering the target application subclass as the object corresponding to the class identifier corresponding to the application to be repaired includes: registering the target application subclass to a spring container, and replacing the object corresponding to the class identifier corresponding to the application to be repaired in the spring container with the target application subclass.
[0008] The application to be repaired is a Controller class or a Mapper class; registering the target application subclass to a spring container and replacing the object corresponding to the class identifier of the application to be repaired in the spring container with the target application subclass includes: registering the target application subclass to a subcontainer of the spring container; and replacing the object corresponding to the class identifier of the application to be repaired in the subcontainer with the target application subclass.
[0009] The application to be repaired is a Controller class; replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass includes: registering the target application subclass in RequestMappingInfoHandlerMapping, wherein the RequestMappingInfoHandlerMapping records the mapping relationship between the target application subclass and the class identifier corresponding to the application to be repaired.
[0010] The application to be repaired is a Mapper class; replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass includes: registering the target application subclass in the Configuration, wherein the Configuration records the mapping relationship between the target application subclass and the class identifier corresponding to the application to be repaired.
[0011] In order to solve the above problems, the second aspect of the present application provides a hot repair system for an application, which includes several terminals and a distributed repair platform connected to each of the terminals; the distributed repair platform is used to obtain the class files of the target application subclass corresponding to the application to be repaired, and distribute the class files of the target application subclass to each of the terminals; the terminal is used to obtain the class files of the target application subclass, and use the hot repair method of the application in the first aspect to hot repair the application to be repaired.
[0012] Among them, the distributed repair platform includes an interconnected file acquisition unit, a security verification unit, a storage unit and a communication circuit; the file acquisition unit is used to automatically pull the class file of the target application subclass corresponding to the application to be repaired according to the class identifier of the application to be repaired; the security verification unit is used to perform security mechanism verification on the class file of the target application subclass; the storage unit is used to store the class file of the target application subclass after the security mechanism verification is passed; the communication circuit is used to distribute the class file of the target application subclass to each of the terminals.
[0013] To solve the above problems, the third aspect of the present application provides an electronic device, which includes a processor and a memory connected to each other; the memory is used to store program instructions, and the processor is used to execute the program instructions to implement the hot repair method of the application of the first aspect above.
[0014] To solve the above problems, the fourth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a processor, implements the hot repair method of the application program of the first aspect.
[0015] The beneficial effects of the present invention are as follows: Different from the prior art, in the hot repair method of the application of the present application, the terminal obtains a patch package of the application to be repaired, which includes the class file of the target application subclass corresponding to the application to be repaired, and then uses a class loader to load the class file of the target application subclass, and registers the target application subclass as the object corresponding to the class identifier corresponding to the application to be repaired. By using the class loader to load the class file of the target application subclass corresponding to the application to be repaired, a subclass of the class to be repaired is implemented, and then the logic or method to be repaired is adjusted on the subclass of the class to be repaired, and then loaded again. Since the object corresponding to the class identifier corresponding to the application to be repaired is replaced with the target application subclass, the original class to be repaired can be used as a bridge to accept the repaired object, and the call of the method or logic of the repaired object can be conveniently completed. In this way, the scenario where the class to be repaired does not implement a certain declared interface is avoided, and the complexity of reference processing in various frameworks caused by subsequent calls to the repair method is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a flow chart of an embodiment of a method for hot repairing an application program of the present application;
[0017] Figure 2 This is a schematic diagram of the structure of an embodiment of a hot repair system for an application program of the present application;
[0018] Figure 3 yes Figure 2 A structural diagram of an embodiment of a distributed repair platform in a hot repair system for an application;
[0019] Figure 4 This is a schematic diagram of the workflow of a hot repair system for an application in an application scenario of the present application;
[0020] Figure 5 This is a structural diagram of an embodiment of an electronic device of the present application;
[0021] Figure 6 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0022] The following describes the embodiments of the present application in detail with reference to the accompanying drawings.
[0023] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0024] The terms "system" and "network" are often used interchangeably in this document. The term "and / or" is simply a description of an association between related objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone. Furthermore, the character " / " generally indicates that the related objects are in an "or" relationship. Furthermore, "multiple" in this document means two or more than two.
[0025] See also Figure 1 , Figure 1 This is a flow chart of an embodiment of a method for hot repairing an application program of the present invention. The method for hot repairing an application program of this embodiment includes the following steps:
[0026] Step S11: the terminal obtains a patch package of the application to be repaired, wherein the patch package includes a class file of a target application subclass corresponding to the application to be repaired.
[0027] Specifically, the application to be repaired is installed in a terminal, which can be an electronic device with computing functions such as a mobile phone or a computer. The terminal has an Internet connection and can receive patches and use the patches to repair the vulnerabilities in the application.
[0028] Step S12: using a class loader to load the class file of the target application subclass.
[0029] Step S13: registering the target application subclass as an object corresponding to the class identifier corresponding to the application to be repaired.
[0030] In the existing solution, when there is a problem with a method in a certain class, for example, there is a problem with class a, the first solution that developers consider is to rewrite class a and then replace the original class a. However, this is problematic, that is, for the same class loader in the JVM, once a class a is started and loaded, it will not allow another class a to be loaded, that is, the same class loader cannot be reloaded; for this, two class loaders can be used, one class loader loads the original class a, and now there is a repaired class a, and another class loader is used to load the repaired class a, but after loading, when calling the repaired class a, a reference to the repaired class a is required, and when the reference to the repaired class a is obtained, it will be considered that these are two classes a loaded by two class loaders, and the two classes a are different; that is, because the security mechanism of JAVA believes that even if different class loaders Even if the same class is loaded, it cannot be assumed that the classes loaded by different class loaders are the same class. This means that the same class loaded by different class loaders cannot be directly assigned or forcibly transferred. Therefore, in the solution of the present application, by generating and loading the class file of the target application subclass corresponding to the application to be repaired, that is, relative to the problematic class A, a subclass of class A is generated and loaded, so when calling the subclass of class A, a reference to the subclass of class A is obtained. At this time, class A and the subclass of class A can be considered to be of the same type, so the original class to be repaired can be used as a bridge to accept the repaired object, and the call of the method of the repaired object can be conveniently completed.
[0031] The above scheme utilizes the class loader to load the class file of the target application subclass corresponding to the application to be repaired, that is, to implement a subclass of the class to be repaired, and then adjusts the logic or method that needs to be repaired on the subclass of the class to be repaired, and then loads it again. Since the object corresponding to the class identifier corresponding to the application to be repaired is replaced with the target application subclass, the original class to be repaired can be used as a bridge to accept the repaired object, and the call of the method or logic of the repaired object can be conveniently completed. This avoids the scenario where the class to be repaired does not implement a certain declared interface, and reduces the complexity of reference processing in various frameworks caused by subsequent calls to the repair method.
[0032] In one embodiment, the above step S12 specifically includes: loading the class file of the target application subclass into the JVM through the class loader. Specifically, the class file of the target application subclass can be loaded into the JVM through the class loader, and then such an object will exist in the JVM.
[0033] In one embodiment, the above step S13 specifically includes: registering the target application subclass to a spring container, and replacing the object corresponding to the class identifier corresponding to the application to be repaired in the spring container with the target application subclass.
[0034] Specifically, the method of the present application can be targeted at Spring-type frameworks, which have containers within them. Each service or functional object is initialized and placed within the Spring container. For example, if the application to be repaired is running an object called object a and one of its methods has a problem, a subclass of object a, namely object b, can be generated, and the problematic method can be repaired. Later, during loading, this subclass of object a can be loaded into the JVM, and then the object corresponding to the name identified by object a in the Spring container can be replaced with the newly loaded object b. In other words, the object corresponding to the class identifier of the application to be repaired in the Spring container is replaced with the target application subclass.
[0035] Furthermore, the application to be repaired is a Controller class or a Mapper class. The above-mentioned step of registering the target application subclass with the spring container and replacing the object corresponding to the class identifier corresponding to the application to be repaired in the spring container with the target application subclass can specifically include: registering the target application subclass with the subcontainer of the spring container; replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass. Specifically, there are subcontainers in the top-level spring container. For the controller layer framework or the Mapper layer framework, the controller layer objects and the Mapper layer objects are registered in the subcontainer, while for other ordinary classes to be repaired, they are directly registered in the top-level spring container.
[0036] When the application to be repaired is a Controller class, the above-mentioned step of replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass specifically includes: registering the target application subclass in RequestMappingInfoHandlerMapping, and the RequestMappingInfoHandlerMapping records the mapping relationship between the target application subclass and the class identifier corresponding to the application to be repaired.
[0037] Specifically, when the application to be repaired is a Controller class, for the Controller layer framework, the Controller object is parsed to obtain the url-Method object to RequestMappingInfoHandlerMapping. At this time, the Controller object is the class to be repaired, and the url-Method object is a subclass of the class to be repaired that has a mapping relationship with the class identifier corresponding to the class to be repaired. Since all classes in the Controller layer will be registered in RequestMappingInfoHandlerMapping, after generating the subclass of the class to be repaired, the registry content of RequestMappingInfoHandlerMapping can be updated, and the mapping relationship between the originally registered class to be repaired and the corresponding class identifier can be registered as a mapping relationship between the subclass of the class to be repaired and the class identifier, so that the hot-repaired Controller object can be called according to the class identifier.
[0038] When the application to be repaired is a Mapper class, the above-mentioned step of replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass specifically includes: registering the target application subclass in the Configuration, and the Configuration records the mapping relationship between the target application subclass and the class identifier corresponding to the application to be repaired.
[0039] Specifically, when the application to be repaired is a Mapper class, for the Mapper layer, the Mybatis framework constructs a proxy object for the Mapper layer. Each time a method of the Mapper layer object is called, the corresponding MappedStatement object is obtained from the Configuration. Based on this principle, the registration information of the Mapper object to be repaired in the Configuration is updated, and the mapping relationship between the originally registered Mapper object to be repaired and the corresponding class identifier is registered as a mapping relationship between the subclass of the class to be repaired and the class identifier, so that the hot-repaired Mapper object can be called according to the class identifier to achieve the purpose of hot repair.
[0040] See also Figure 2 , Figure 2The present invention is a schematic diagram of the structure of an embodiment of a hot repair system for an application of the present invention. The hot repair system 20 for an application in this embodiment includes a plurality of terminals 200 and a distributed repair platform 202 connected to each of the terminals 200. The distributed repair platform 202 is configured to obtain the class files of a target application subclass corresponding to the application to be repaired and distribute the class files of the target application subclass to each of the terminals 200. The terminals 200 are configured to obtain the class files of the target application subclass and perform hot repair on the application to be repaired using any of the aforementioned hot repair methods for the application.
[0041] It is understandable that after a production environment problem is discovered during the use of the terminal 200, the bug can be repaired offline. Specifically, after obtaining the application to be repaired, the class file of the target application subclass corresponding to the application to be repaired can be compiled offline, and then the class file of the target application subclass can be placed on the distributed repair platform 202; then the distributed repair platform 202 will push the compiled class file of the target application subclass to each terminal 200 online; and after the terminal 200 obtains the class file of the target application subclass, it can use any of the above-mentioned hot repair methods of the application to perform hot repair on the application to be repaired.
[0042] Please combine Figure 3 , Figure 3 yes Figure 2 A structural diagram of an embodiment of a distributed repair platform in a hot repair system for an application. In one embodiment, the distributed repair platform 202 includes a file acquisition unit 2021, a security verification unit 2022, a storage unit 2023, and a communication circuit 2024 that are interconnected; the file acquisition unit 2021 is used to automatically pull the class file of the target application subclass corresponding to the application to be repaired based on the class identifier of the application to be repaired; the security verification unit 2022 is used to perform a security mechanism verification on the class file of the target application subclass; the storage unit 2023 is used to store the class file of the target application subclass after the security mechanism verification is passed; and the communication circuit 2024 is used to distribute the class file of the target application subclass to each of the terminals 200.
[0043] Please combine Figures 2 to 4 , Figure 4This is a workflow diagram of a hot repair system for an application in an application scenario of the present application. Specifically, after a production environment problem is discovered during the use of a terminal 200, since the developer has the source code, after determining the application to be repaired, the source code can be directly modified offline to fix the bug through reproduction and debugging, and then a class file of a target application subclass corresponding to the application to be repaired is compiled; the file acquisition unit 221 of the distributed repair platform 202 can then automatically pull the class file of the target application subclass according to the class identifier of the application to be repaired, and the security verification unit 222 can perform a security mechanism verification on the class file of the target application subclass. After the security mechanism verification passes, the class file of the target application subclass can be encrypted, compressed and uploaded to the distributed repair platform 202; thereafter, the distributed repair platform 202 can distribute the class file of the target application subclass to each terminal 200 through the communication circuit 224; and after obtaining the class file of the target application subclass, the terminal 200 can use its respective repair program hardware (hotfixAgent) to execute any of the above-mentioned hot repair methods for the application to be repaired to hot repair the application to be repaired. The hot repair system 20 of the application of the present application can repair a wide range of system components, for example, it can modify method bodies, method signatures, and can also delete and add method / class member attributes; in addition, the system has good stability. Compared with the javaAgent method that directly modifies the entire JVM level, the hot repair system 20 of the application of the present application only affects the local scope of the repair, and the impact range can be controlled when unknown problems occur; the hot repair method of the application of the present application uses the class to be repaired as a bridge, and the repaired subclass can directly call the repaired method, avoiding the limitation of the class to be repaired having no declared interface, and reducing the complexity of reference dependencies and other problems; and the hot repair system 20 of the application of the present application can automatically publish the repair code, and by adding a security inspection mechanism to review the class files of the target application subclass, it can avoid security issues caused by the hot repair function.
[0044] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 50 in this embodiment includes a processor 502 and a memory 501 connected to each other. The memory 501 is used to store program instructions, and the processor 502 is used to execute the program instructions stored in the memory 501 to implement the steps of the embodiment of the hot repair method for any application described above. In a specific implementation scenario, the electronic device 50 may include, but is not limited to, a microcomputer or a server.
[0045] Specifically, the processor 502 is used to control itself and the memory 501 to implement the steps of the embodiment of the hot repair method of any of the above-mentioned applications. The processor 502 can also be called a CPU (Central Processing Unit). The processor 502 may be an integrated circuit chip with signal processing capabilities. The processor 502 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 502 can be implemented by an integrated circuit chip.
[0046] See also Figure 6 , Figure 6 The computer-readable storage medium 60 of the present invention stores program instructions 600 thereon, which, when executed by a processor, implement the steps of any of the above-mentioned application program hot repair method embodiments.
[0047] The computer-readable storage medium 60 can specifically be a medium that can store program instructions 600, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, or it can also be a server that stores the program instructions 600. The server can send the stored program instructions 600 to other devices for execution, or it can also execute the stored program instructions 600 itself.
[0048] In the several embodiments provided in this application, it should be understood that the disclosed methods, devices and apparatuses can be implemented in other ways. For example, the above-described device and apparatus implementation methods are merely schematic. For example, the division of modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0049] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0050] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0051] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
Claims
1. A method for hot repairing an application, characterized in that: The hot fix method for the application includes: The terminal obtains a patch package of the application to be repaired, wherein the patch package includes a class file of a target application subclass corresponding to the application to be repaired; the application to be repaired is a Controller class or a Mapper class; Using a class loader to load the class file of the target application subclass; Registering the target application subclass as an object corresponding to the class identifier corresponding to the application to be repaired; The step of loading the class file of the target application subclass by using a class loader comprises: loading the class file of the target application subclass into a JVM by using the class loader; Registering the target application subclass as the object corresponding to the class identifier corresponding to the application to be repaired includes: registering the target application subclass in a subcontainer of a spring container; and replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass.
2. The hot repair method of the application according to claim 1, characterized in that: The application to be repaired is a Controller class; and replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass includes: The target application subclass is registered in RequestMappingInfoHandlerMapping, where the RequestMappingInfoHandlerMapping records a mapping relationship between the target application subclass and a class identifier corresponding to the application to be repaired.
3. The hot repair method of an application according to claim 1, characterized in that: The application to be repaired is a Mapper class; and replacing the object corresponding to the class identifier corresponding to the application to be repaired in the subcontainer with the target application subclass includes: The target application subclass is registered in Configuration, where the Configuration records a mapping relationship between the target application subclass and a class identifier corresponding to the application to be repaired.
4. A hot repair system for an application, characterized in that: The application program's hot repair system includes a plurality of terminals and a distributed repair platform connected to each of the terminals; The distributed repair platform is used to obtain the class file of the target application subclass corresponding to the application to be repaired, and distribute the class file of the target application subclass to each of the terminals; The terminal is used to obtain the class file of the target application subclass, and perform hot repair on the application to be repaired using the hot repair method of the application according to any one of claims 1 to 3.
5. The application program hot repair system according to claim 4, characterized in that: The distributed repair platform includes a file acquisition unit, a security verification unit, a storage unit and a communication circuit that are interconnected; The file acquisition unit is used to automatically pull the class file of the target application subclass corresponding to the application to be repaired according to the class identifier of the application to be repaired; The security verification unit is used to perform security mechanism verification on the class file of the target application subclass; The storage unit is used to store the class file of the target application subclass after the security mechanism verification is passed; The communication circuit is used to distribute the class file of the target application subclass to each of the terminals.
6. An electronic device, characterized in that: The electronic device includes a processor and a memory connected to each other; The memory is used to store program instructions, and the processor is used to execute the program instructions to implement the hot repair method for the application program according to any one of claims 1 to 3.
7. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the hot repair method for the application program according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Application hotfix method and terminal
CN106648724A
Hot repair method, device and equipment and computer readable storage medium
CN110321135A