CN117609084A - Class conflict detection method, device and equipment for application program and storage medium - Google Patents
Class conflict detection method, device and equipment for application program and storage medium Download PDFInfo
- Publication number
- CN117609084A CN117609084A CN202311657756.9A CN202311657756A CN117609084A CN 117609084 A CN117609084 A CN 117609084A CN 202311657756 A CN202311657756 A CN 202311657756A CN 117609084 A CN117609084 A CN 117609084A
- Authority
- CN
- China
- Prior art keywords
- class
- name
- target
- target class
- application program
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000001514 detection method Methods 0.000 title claims abstract description 30
- 238000000034 method Methods 0.000 claims abstract description 95
- 238000011068 loading method Methods 0.000 claims abstract description 72
- 238000004590 computer program Methods 0.000 claims description 16
- 230000008569 process Effects 0.000 claims description 14
- 238000013461 design Methods 0.000 claims description 11
- 238000010200 validation analysis Methods 0.000 claims description 8
- 238000012545 processing Methods 0.000 description 9
- 238000004891 communication Methods 0.000 description 8
- 230000003068 static effect Effects 0.000 description 6
- 238000010586 diagram Methods 0.000 description 5
- 230000001419 dependent effect Effects 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000004422 calculation algorithm Methods 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 230000018109 developmental process Effects 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000004044 response Effects 0.000 description 2
- 238000012546 transfer Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 239000000969 carrier Substances 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 239000006185 dispersion Substances 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000014509 gene expression Effects 0.000 description 1
- 239000011521 glass Substances 0.000 description 1
- 230000008140 language development Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000007670 refining Methods 0.000 description 1
- 238000013515 script Methods 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000011895 specific detection Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3604—Software analysis for verifying properties of programs
- G06F11/3612—Software analysis for verifying properties of programs by runtime analysis
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The embodiment of the invention discloses a method, a device, equipment and a storage medium for detecting class conflict of an application program. The method comprises the following steps: acquiring a target class name which needs class conflict inquiry; dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs; determining the same-name class position matched with the target class name in the running environment of the application program; and generating a class conflict query result for the target class name according to the actual effective position and the homonymy position of the target class name. The technical scheme provided by the embodiment of the invention is used for improving the detection efficiency of conflict classes.
Description
Technical Field
The embodiment of the invention relates to the field of Java application technology development, in particular to a class conflict detection method, device and equipment for an application program and a storage medium.
Background
Java is used as an object-oriented programming language, has the characteristics of powerful functions, simplicity and easiness in use, and is widely applied. When the Java language development application program is selected, the class loader is used for loading the classes required by Java operation into a Java virtual machine (Java Virtual Machine, JVM) for execution. In the actual development process, when the Java application program fails to load the correct class for some reason, the running result of the related program code is inconsistent with the expected result, and the class conflict is considered to occur. Class conflicts can also be defined simply as class loading errors caused by the dispersion of Java classes of the same name in different locations or carriers on the class loading path under the same namespace. Class conflict problems are typically caused by the JVM loading and using the class of the same name that the application does not want to use, resulting in a program misprediction.
In the prior art, detection of Java class conflicts is mostly in a static manner. Taking maven as an example, the maven uses GAV (Group ID, artifact Version, revision) to uniquely identify all dependent items in a maven item, and in the compiling process, the maven uses GAV information to search the dependent items and generate corresponding construction scripts, when repeated introducing components with the same GA but different V exist, a corresponding dependent conflict resolution mechanism exists in the maven to determine a specific effective Version V. When a component changes G or V for some reason, maven's dependency conflict detection cannot identify that the new and old versions of the component are identical. In addition, since the runtime environment, such as Tomcat/WebSphere, is also JVM-based, there are packages in the runtime environment that may have class conflicts. Because static detection cannot include an actual running environment, class conflicts which occur during running cannot be detected naturally, namely, a static mode cannot identify potential class conflict situations with the running environment, even if the running environment has a class loading priority design. Therefore, when the class conflict detection is performed in this way, there are many limitations in static detection of the class conflict, so that the class conflict detection efficiency is low.
Disclosure of Invention
The invention provides a class conflict detection method, device and equipment of an application program and a storage medium, so as to improve the detection efficiency of conflict class.
In a first aspect, an embodiment of the present invention provides a method for detecting a class conflict of an application program, where the method includes:
acquiring a target class name which needs class conflict inquiry;
dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs;
determining the same-name class position matched with the target class name in the running environment of the application program;
and generating a class conflict query result for the target class name according to the actual effective position of the target class name and the homonym position.
In a second aspect, an embodiment of the present invention further provides an apparatus for detecting a class conflict of an application program, where the apparatus includes:
the information acquisition module is used for acquiring a target class name which needs to be subjected to class conflict inquiry;
the position determining module is used for dynamically loading the target class by adopting the target class name and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs;
The same-name position determining module is used for determining the same-name class position matched with the target class name in the running environment of the application program;
and the result generation module is used for generating a class conflict query result for the target class name according to the actual effective position of the target class name and the homonym position.
In a third aspect, an embodiment of the present invention further provides an electronic device, including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform a method of collision-like detection of an application of any of the embodiments of the present invention.
In a fourth aspect, embodiments of the present invention further provide a storage medium containing computer-executable instructions that, when executed by a computer processor, enable the computer processor to perform any one of the application programs provided by the embodiments of the present invention.
The embodiment of the invention obtains the target class name which needs to be subjected to class conflict inquiry; dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs; determining the same-name class position matched with the target class name in the running environment of the application program; and generating a class conflict query result for the target class name according to the actual effective position and the homonymy position of the target class name. The technical scheme provided by the embodiment of the invention is used for improving the detection efficiency of conflict classes.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the invention or to delineate the scope of the invention. Other features of the present invention will become apparent from the description that follows.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for detecting class conflict of an application program according to a first embodiment of the present invention;
FIG. 2 is a flowchart of another method for detecting a class conflict of an application program according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of an apparatus for detecting a collision of application programs according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to a method for detecting a collision of application programs according to a fourth embodiment of the present invention.
Detailed Description
In order that those skilled in the art will better understand the present invention, a technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In addition, it should be noted that, in the technical scheme of the invention, the related processes of collection, storage, use, processing, transmission, provision, disclosure and the like of the related data and the like all conform to the regulations of related laws and regulations and do not violate the popular regulations.
Example 1
Fig. 1 is a flowchart of a method for detecting a class conflict of an application program according to an embodiment of the present invention, where the method may be applied to a case of detecting a conflict class, and the method may be performed by a device for detecting a class conflict of an application program, where the device for detecting a class conflict of an application program may be implemented in a form of hardware and/or software, and the device for detecting a class conflict of an application program may be configured in an electronic device, and the electronic device may be a terminal device or a server, and the embodiment of the present invention is not limited to this.
As shown in fig. 1, the method for detecting class conflict of an application program provided by the embodiment of the invention specifically includes the following steps:
s110, obtaining the target class name which needs to be subjected to class conflict query.
Specifically, in response to the demand of the demand party for querying the class conflict, the class name to be queried for the class conflict can be obtained, that is, the target class name to be queried for the class conflict is obtained.
The method for obtaining the target Class name may be that Class names input by a demander having a Class conflict query requirement are loaded by a Class #forname method in Java.
The target class name which needs to be subjected to class conflict query is obtained so as to facilitate the subsequent processing of the target class name, and thus the query on whether the class conflict exists in the target class name is realized.
S120, dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs.
Specifically, according to the obtained target class name, the target class corresponding to the target class name can be obtained in a dynamic loading mode, and the actual effective position of the target class name in the application program is determined according to the dynamic loading information. It is understood that dynamic loading may be understood specifically as loading in a manner that is acquired in real time, as opposed to static loading. It should be noted that, when determining the actual effective position of the target class name in the application program according to the dynamic loading information, the loaded target class is not necessarily the class that needs to be loaded in the application program, which is not limited by the embodiment of the present invention.
In particular, when determining the actual effective location of the target class name in the application, the restriction of the Java security authority is easily included, but not limited, so that the query result cannot be obtained, that is, the corresponding actual effective location cannot be obtained. Therefore, unlike the above determination of the actual effective position of the target class name in the application program, the actual effective position of the target class name in the application program may also be determined according to the class loader to which the target class name belongs.
Dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs. The actual effective position of the target class name in the application program can be determined in any one of the two manners, so that the obtained actual effective position is more accurate, and the determination efficiency of the actual effective position is improved.
S130, determining the same-name class position matched with the target class name in the running environment of the application program.
And S140, generating a class conflict query result for the target class name according to the actual effective position of the target class name and the homonym position.
Specifically, by determining the homonym position matched with the target class name in the running environment of the application program, the class conflict of the target class name can be queried according to the actual effective position and the homonym position of the target class name, and then a class conflict query result of the target class name is generated, so that the detection efficiency of the conflict class is improved.
The embodiment of the invention obtains the target class name which needs to be subjected to class conflict inquiry; dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs; determining the same-name class position matched with the target class name in the running environment of the application program; and generating a class conflict query result for the target class name according to the actual effective position and the homonymy position of the target class name. The technical scheme provided by the embodiment of the invention is used for improving the detection efficiency of conflict classes.
Example two
Fig. 2 is a flowchart of another method for detecting a collision of an application program according to a second embodiment of the present invention, where the technical solution of the embodiment of the present invention is further optimized based on the foregoing alternative technical solutions.
Further, dynamically loading the target class by adopting the target class name, and determining the target class position of the currently effective target class in the application program according to the dynamic loading information; or determining the target class position of the currently effective target class in the application program by adopting a class loader to which the target class name belongs, further refining into' carrying out class loading by adopting the target class name, and determining the actual effective class and the actual effective position of the target class name in the application program according to a class loading result; if the actual effective position of the target class name in the application program is not obtained according to the loading result, a target class loader to which the target class name belongs is obtained, and the actual effective position' of the target class name in the application program is determined by adopting the target class loader, so that the detection efficiency of the conflict class is improved. It should be noted that, in the present embodiment, parts not described in the present embodiment may refer to the related expressions of other embodiments, which are not described herein.
As shown in fig. 2, another method for detecting a class conflict of an application program according to an embodiment of the present invention specifically includes the following steps:
s210, obtaining a target class name which needs to be subjected to class conflict query.
S220, carrying out class loading by adopting the target class name, and determining the actual effective class and the actual effective position of the target class name in the application program according to the class loading result.
Specifically, in response to the requirement of inquiring the class conflict, the class name, namely the target class name, required to be inquired about the class conflict can be firstly obtained, then the obtained target class name is loaded, and the actual effective class and the actual effective position of the target class name in the application program are determined according to the class loading result.
Optionally, class loading is performed by using the target class name, and an actual effective class and an actual effective position of the target class name in the application program are determined according to a class loading result, including: class loading is carried out by adopting a target class name, and an actual effective class of the target class name in the application program and a target class object of the actual effective class are obtained; calling a protection domain object acquisition method in the target class object to obtain a target protection domain object; calling a code source object acquisition method in the target protection domain object to obtain a target code source object; and calling a position acquisition method in the target code source object to obtain an actual effective class and an actual effective position of the target class name in the application program.
Specifically, by carrying out class loading on the target class name, when the actual effective class and the actual effective position of the target class name in the application program are determined according to the class loading result, a protection domain object acquisition method in the target class object can be called, after the target protection domain object is obtained, a code source object acquisition method in the target protection domain object can be called, after the target code source object is obtained, a position acquisition method in the target code source object can be called, and the actual effective class and the actual effective position of the target class name in the application program can be obtained.
Illustratively, when the actual validation class and the actual validation position of the target class name in the application program are acquired, the Java security. Then, the java.security.CodeSource object, namely the code source object of the target class is obtained by calling a getCodeSource () method in the ProtectionDomain object; then, the java.net.url object can be obtained by calling the getLocation () method in the CodeSource, and the returned result is the location of the target class file, that is, the actual effective location of the target class name in the application program, where the location may be, but is not limited to, a class directory, a jar file, or a zip file.
The method comprises the steps of obtaining a target class name needing class conflict query, carrying out class loading on the target class name, and calling a protection domain object obtaining method in a target class object to obtain a target protection domain object; calling a code source object acquisition method in the target protection domain object to obtain a target code source object; and calling a position acquisition method in the target code source object to obtain the actual effective class and the actual effective position of the target class name in the application program, so that the more comprehensive actual effective class and the actual effective position information of the target class name in the application program can be acquired in an automatic real-time query mode, and the searching efficiency of the actual effective class and the actual effective position information is improved.
And S230, if the actual effective position of the target class name in the application program is not obtained according to the loading result, acquiring a target class loader to which the target class name belongs, and determining the actual effective position of the target class name in the application program by adopting the target class loader.
Specifically, if the actual effective position of the target class name in the application program is not obtained according to the loading result, the target class loader to which the target class name belongs can be obtained, and then the actual effective position of the target class name in the application program is determined.
Optionally, determining the actual effective position of the target class name in the application program by using the target class loader includes: acquiring an instance name of a class loader to which the target class name belongs; if the instance name of the class loader exists, calling a resource acquisition method in the instance name of the class loader to obtain the actual effective position of the target class name in the application program; and if the instance name of the class loader does not exist, calling a system resource acquisition method of the class loader to obtain the actual effective position of the target class name in the application program.
Specifically, when determining the actual effective position of the target class name in the application program according to the target class loader, the instance name of the class loader to which the target class name belongs can be acquired first, if the instance name of the class loader exists, a resource acquisition method in the instance name of the class loader can be called, and then the actual effective position of the target class name in the application program can be obtained; if the instance name of the class loader does not exist, the actual effective position of the target class name in the application program can be obtained by calling a system resource acquisition method of the class loader.
For example, when determining the actual effective position of the target class name in the application program according to the target class loader, the instance name of the Java class loader to which the target class name belongs can be obtained through a ClassLoader CL method in Java, if the instance name of the Java class loader exists, the instance Resource obtaining class position of the class loader can be obtained through calling a Resource () method of ClassLoaderget in the instance name of the Java class loader, and then the actual effective position of the target class name in the application program can be obtained; if the instance name of the Java class loader does not exist, the system resource can be obtained by calling a getSystemResource () method in the class of the class loader, and then the actual effective position of the target class name in the application program can be obtained. It should be noted that, the embodiment of the present invention does not limit the determination manner of determining the actual effective position of the target class name in the application program according to the target class loader.
It should be noted that, for the design of the collision-like query online interface, the design may be performed by hypertext transfer protocol (Hyper Text Transfer Protocol, HTTP), and for example, the design manner of the interface may be:
@RequestMapping(value="/clsldrsrc/{clsFulnam}",method=RequestMethod.GET)
public HttpApiResponse clsLdrSrc(@PathVariable String clsFulnam){
Wherein the class full name parameter is replaced by @.
If the actual effective position of the target class name in the application program is not obtained according to the loading result, acquiring a target class loader to which the target class name belongs, and acquiring an instance name of the class loader to which the target class name belongs; if the instance name of the class loader exists, calling a resource acquisition method in the instance name of the class loader; if the instance name of the class loader does not exist, a system resource acquisition method of the class loader is called. In summary, the actual effective position of the target class name in the application program can be obtained according to the target class loader. The method can comprehensively acquire the actual effective position of the target class name in an automatic mode, and further improves the efficiency of acquiring the actual effective position of the target class name in the application program.
S240, determining the same-name class position matched with the target class name in the running environment of the application program.
Specifically, the same-name class location that matches the target class name may be determined based on the application's operating environment.
By way of example, ALL resources of the target class name may be obtained by calling the getResources () method of the ClassLoader in Java, where the returned type is a set of java.net.url objects, and the obtained class location is denoted as l_all, that is, ALL locations of the class may be obtained in the running environment of the application, or the class location in the running environment of the application consistent with the target class name may be obtained. The embodiment of the invention does not limit the calling method of all the resources for acquiring the target class name.
And determining the homonym position matched with the target class name in the running environment of the application program so as to improve the matching efficiency of the homonym position, and further carrying out subsequent processing according to the obtained homonym position.
S250, generating a class conflict query result for the target class name according to the actual effective position of the target class name and the homonym position.
Specifically, a class conflict query result for the target class name may be generated according to the actual effective location and the homonym location of the target class name.
When generating the class conflict query result of the target class name, the actual validation position and the homonym position of the acquired target class name can be judged, that is, if the acquired homonym position is unique and consistent with the actual validation position of the target class name, the class conflict query result of the target class name can be considered as that the class conflict condition does not exist; if the obtained class position with the same name is not unique, that is, at least one class position with the same name exists, the class conflict query result of the target class name can be considered to be that the class conflict exists. Particularly, when the class conflict situation is determined to exist, a class conflict signal can be sent out in a page display mode, and the same-name class position is displayed in a popup window mode.
Optionally, the method for detecting a class conflict of an application program described in this embodiment further includes: in the starting process of an application program, acquiring a current class which is being executed, and acquiring parent class loaders of each layer of the current class as class loaders to be scanned of the current class; acquiring the occurrence times and the corresponding class positions of the current class scanned by a class loader to be scanned of the current class, and acquiring the repeated positions of the current class according to the occurrence times and the class positions of the current class; acquiring an actual effective position of a current class which is actually effective in an application program; and obtaining a conflict scanning result of the current class according to the name of the current class, the actual effective position of the current class and the repeated position of the current class.
Specifically, in the starting process of the application program, the class conflict condition can be detected, and a specific detection mode can be that the current class which is being executed is obtained, each layer of parent class loader of the current class is used as the class loader to be scanned of the current class, and the repetition position of the current class can be obtained by obtaining the occurrence times of the current class scanned by the class loader to be scanned of the current class and the corresponding class position. And secondly, acquiring the actual effective position of the current class which is actually effective in the application program, and obtaining a conflict scanning result of the current class according to the name of the current class, the actual effective position of the current class and the repeated position of the current class. The embodiment of the invention does not limit the detection mode for detecting the class conflict in the starting process of the application program.
In the starting process of the application program, the current class which is being executed is acquired and recorded through class loaders, and as each class loader class has a reference pointing to a parent class loader, the complete structure of class loader hierarchy can be acquired from the class loader of the current class. It should be noted that, each class loader of each hierarchy has its own class loading path, and the specific implementation classes of the class loader are different, and the acquisition methods are also different. Because of the application scenarios, the loading paths of some class loaders may be empty. And secondly, obtaining information of all classes under the loading range of each class loader, and recording the occurrence times and positions of the classes. In the process of reading traversal, if the full name of the class is repeated with the counted class, and the full name of the class is the complete path information of the class obtained by combining the path of the class and the name of the class, the class is considered to have the possibility of collision. That is, for each class loader, the number of occurrences, location, and directory information of the class scanned by the class loader may be acquired. So far, all other duplicate paths with which the current class may have duplicate paths are available.
Then, the actual verification may be performed in a dynamic class loading manner by calling the java. Lang. Class for name () method, where the dynamic class loading method returns an actual loading path that the class object may find, that is, the obtaining manner in which the location of the currently valid class is obtained may be determined by the methods described in S210, S220, and S230, which is not limited in this embodiment of the present invention. So far, the actual effective path of the current class can be obtained.
To this end, for each conflicting class, a corresponding triplet is obtained, which consists of class name-actual validation path-other duplicate path.
Optionally, the method further comprises: a common interface of conflict scanning is adopted to acquire configuration information of the conflict scanning, and the configuration information of the conflict scanning is adopted to carry out collision-like scanning; the common interface of the conflict scanning is constructed by adopting a bridging design mode for rule judgment, configuration parameter reading or result output.
Specifically, after the configuration information of the conflict scan is obtained by adopting the public interface of the conflict scan, the conflict-like scan can be performed according to the obtained configuration information of the conflict scan. The common interface for conflict scanning can be designed in a bridging design mode, namely, rules are judged, configuration parameters are read or output results are constructed. The method is realized by taking rule judgment, configuration parameter reading and result output as public interfaces and giving the public interfaces to an application system, and the main class loader hierarchical acquisition, class loading path traversal and conflict class detection are used as core tool class realization and are provided in a unified interface mode. Particularly, in the class conflict scanning algorithm, priority can be set so as to trigger a calling method of the interface when the interface is started, so that the SpringBoot application is adapted.
By using the bridge design mode, the scanning device has flexibility in scanning, and further improves the overall scanning effect.
If the actual effective position of the target class name in the application program is not obtained according to the loading result, the embodiment of the invention acquires the target class loader to which the target class name belongs and acquires the instance name of the class loader to which the target class name belongs; if the instance name of the class loader exists, calling a resource acquisition method in the instance name of the class loader; and if the instance name of the class loader does not exist, calling a system resource acquisition method of the class loader to obtain the actual effective position of the target class name in the application program. By determining the class location of the same name that matches the target class name in the application's operating environment, class conflict query results for the target class name may be generated. In the starting process of the application program, the current class which is being executed can be obtained, and parent class loaders of all layers of the current class are obtained and used as class loaders to be scanned of the current class; the actual effective position of the current class in the application program can be obtained by obtaining the occurrence times of the current class, the corresponding class position and the repeated position of the current class, and then the conflict scanning result of the current class is obtained according to the name of the current class, the actual effective position of the current class and the repeated position of the current class. A common interface of conflict scanning is adopted to acquire configuration information of the conflict scanning, and the configuration information of the conflict scanning is adopted to carry out collision-like scanning; the common interface of the conflict scanning is constructed by adopting a bridging design mode for rule judgment, configuration parameter reading or result output. The technical scheme provided by the embodiment of the invention not only can specify the specific class name to perform class conflict check during operation, but also can set to start the checking of the total quantity of class conflicts after the application is started. Through detecting in the operation, the existence of the class conflict can be more effectively detected relative to the static detection, and the operation risk is reduced so as to improve the detection efficiency of the conflict class.
Example III
Fig. 3 is a schematic structural diagram of an apparatus for detecting collision of application programs according to a third embodiment of the present invention. As shown in fig. 3, the apparatus for detecting class conflict of an application program includes: an information acquisition module 310, a location determination module 320, a homonymous location determination module 330, and a result generation module 340. Wherein:
an information obtaining module 310, configured to obtain a target class name that needs to be queried for a class conflict;
the location determining module 320 is configured to dynamically load the target class by using the target class name, and determine an actual effective location of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs;
the same name location determining module 330 is configured to determine a same name class location matching the target class name in the running environment of the application program;
and the result generating module 340 is configured to generate a class conflict query result for the target class name according to the actual effective location of the target class name and the peer class location.
The embodiment of the invention obtains the target class name which needs to be subjected to class conflict inquiry; dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs; determining the same-name class position matched with the target class name in the running environment of the application program; and generating a class conflict query result for the target class name according to the actual effective position and the homonymy position of the target class name. The technical scheme provided by the embodiment of the invention is used for improving the detection efficiency of conflict classes.
Optionally, the location determining module 320 includes:
the class and position determining unit is used for carrying out class loading by adopting the target class name and determining the actual effective class and the actual effective position of the target class name in the application program according to the class loading result;
and the actual position determining unit is used for acquiring a target class loader to which the target class name belongs and determining the actual effective position of the target class name in the application program by adopting the target class loader if the actual effective position of the target class name in the application program is not obtained according to the loading result.
Optionally, the class and position determining unit comprises:
the class loading subunit is used for carrying out class loading by adopting the target class name to obtain an actual effective class of the target class name in the application program and a target class object of the actual effective class;
an object obtaining subunit, configured to invoke a protection domain object obtaining method in the target class object to obtain a target protection domain object;
a source object obtaining subunit, configured to invoke a code source object obtaining method in the target protection domain object to obtain a target code source object;
the actual information obtaining subunit is used for calling a position obtaining method in the target code source object to obtain an actual effective class and an actual effective position of the target class name in the application program.
Optionally, the actual position determining unit includes:
an instance name obtaining subunit, configured to obtain an instance name of a class loader to which the target class name belongs;
the name existence subunit is used for calling a resource acquisition method in the instance name of the class loader if the instance name of the class loader exists, so as to obtain the actual effective position of the target class name in the application program;
and the name non-existence subunit is used for calling a system resource acquisition method of the class loader if the name of the instance of the class loader does not exist, so as to obtain the actual effective position of the target class name in the application program.
Optionally, the method further includes a collision result obtaining module, including:
the class loader acquisition unit is used for acquiring the current class being executed in the starting process of the application program, and acquiring parent class loaders of all layers of the current class as class loaders to be scanned of the current class;
the repeated position acquisition unit is used for acquiring the occurrence times of the current class and the corresponding class position scanned by the class loader to be scanned by the current class, and acquiring the repeated position of the current class according to the occurrence times of the current class and the class position;
the effective position acquisition unit is used for acquiring the actual effective position of the current class which is actually effective in the application program;
The scanning result obtaining unit is used for obtaining the conflict scanning result of the current class according to the name of the current class, the actual effective position of the current class and the repeated position of the current class.
Further, the method further comprises an information configuration module, specifically configured to:
a common interface of conflict scanning is adopted to acquire configuration information of the conflict scanning, and the configuration information of the conflict scanning is adopted to carry out collision-like scanning; the common interface of the conflict scanning is constructed by adopting a bridging design mode for rule judgment, configuration parameter reading or result output.
The device for detecting the class conflict of the application program provided by the embodiment of the invention can execute the class conflict detection method of the application program provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Example IV
Fig. 4 shows a schematic diagram of an electronic device 400 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. Electronic equipment may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 4, the electronic device 400 includes at least one processor 410, and a memory, such as a Read Only Memory (ROM) 420, a Random Access Memory (RAM) 430, etc., communicatively coupled to the at least one processor 410, wherein the memory stores computer programs executable by the at least one processor, and the processor 410 may perform various suitable actions and processes according to the computer programs stored in the Read Only Memory (ROM) 420 or the computer programs loaded from the storage unit 480 into the Random Access Memory (RAM) 430. In (RAM) 430, various programs and data required for the operation of electronic device 400 may also be stored. The processors 410, (RAM) 420, and (RAM) 430 are connected to each other by a bus 440. An input/output (I/O) interface 450 is also connected to bus 440.
Various components in electronic device 400 are connected to I/O interface 450, including: an input unit 460 such as a keyboard, a mouse, etc.; an output unit 470 such as various types of displays, speakers, and the like; a storage unit 480 such as a magnetic disk, an optical disk, or the like; and a communication unit 490, such as a network card, modem, wireless communication transceiver, etc. The communication unit 490 allows the electronic device 400 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunications networks.
Processor 410 can be a variety of general-purpose and/or special-purpose processing components having processing and computing capabilities. Some examples of processor 410 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, digital Signal Processors (DSPs), and any suitable processor, controller, microcontroller, etc. The processor 410 performs the various methods and processes described above, such as a class conflict detection method for an application.
In some embodiments, a method of collision-like detection of an application may be implemented as a computer program tangibly embodied on a computer-readable storage medium, such as storage unit 480. In some embodiments, part or all of the computer program may be loaded and/or installed onto electronic device 400 via (RAM) 420 and/or communication unit 490. When a computer program is loaded into (RAM) 430 and executed by processor 410, one or more steps of a class conflict detection method for an application program as described above may be performed. Alternatively, in other embodiments, processor 410 may be configured to perform a method of class conflict detection for an application in any other suitable manner (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
A computer program for carrying out methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be implemented. The computer program may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical hosts and VPS service are overcome.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps described in the present invention may be performed in parallel, sequentially, or in a different order, so long as the desired results of the technical solution of the present invention are achieved, and the present invention is not limited herein.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.
Claims (10)
1. A method for detecting class conflict of an application program, comprising:
acquiring a target class name which needs class conflict inquiry;
dynamically loading the target class by adopting the target class name, and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs;
Determining the same-name class position matched with the target class name in the running environment of the application program;
and generating a class conflict query result for the target class name according to the actual effective position of the target class name and the homonym position.
2. The method of claim 1, wherein the target class is dynamically loaded by using the target class name, and the target class position of the currently effective target class in the application program is determined according to the dynamic loading information; or determining the target class position of the currently effective target class in the application program by adopting a class loader to which the target class name belongs, including:
carrying out class loading by adopting a target class name, and determining the actual effective class and the actual effective position of the target class name in the application program according to a class loading result;
and if the actual effective position of the target class name in the application program is not obtained according to the loading result, acquiring a target class loader to which the target class name belongs, and determining the actual effective position of the target class name in the application program by adopting the target class loader.
3. The method of claim 2, wherein performing class loading using the target class name, and determining an actual validation class and an actual validation location of the target class name in the application program according to a class loading result, comprises:
Class loading is carried out by adopting a target class name, and an actual effective class of the target class name in the application program and a target class object of the actual effective class are obtained;
calling a protection domain object acquisition method in the target class object to obtain a target protection domain object;
calling a code source object acquisition method in the target protection domain object to obtain a target code source object;
and calling a position acquisition method in the target code source object to obtain an actual effective class and an actual effective position of the target class name in the application program.
4. The method of claim 2, wherein determining the actual validation location of the target class name in the application using the target class loader comprises:
acquiring an instance name of a class loader to which the target class name belongs;
if the instance name of the class loader exists, calling a resource acquisition method in the instance name of the class loader to obtain the actual effective position of the target class name in the application program;
and if the instance name of the class loader does not exist, calling a system resource acquisition method of the class loader to obtain the actual effective position of the target class name in the application program.
5. The method of any one of claims 1-4, further comprising:
In the starting process of an application program, acquiring a current class which is being executed, and acquiring parent class loaders of each layer of the current class as class loaders to be scanned of the current class;
acquiring the occurrence times and the corresponding class positions of the current class scanned by a class loader to be scanned of the current class, and acquiring the repeated positions of the current class according to the occurrence times and the class positions of the current class;
acquiring an actual effective position of a current class which is actually effective in an application program;
and obtaining a conflict scanning result of the current class according to the name of the current class, the actual effective position of the current class and the repeated position of the current class.
6. The method as recited in claim 5, further comprising:
a common interface of conflict scanning is adopted to acquire configuration information of the conflict scanning, and the configuration information of the conflict scanning is adopted to carry out collision-like scanning; the common interface of the conflict scanning is constructed by adopting a bridging design mode for rule judgment, configuration parameter reading or result output.
7. A collision-like detection apparatus for an application program, comprising:
the information acquisition module is used for acquiring a target class name which needs to be subjected to class conflict inquiry;
the position determining module is used for dynamically loading the target class by adopting the target class name and determining the actual effective position of the target class name in the application program according to the dynamic loading information; or determining the actual effective position of the target class name in the application program by adopting a class loader to which the target class name belongs;
The same-name position determining module is used for determining the same-name class position matched with the target class name in the running environment of the application program;
and the result generation module is used for generating a class conflict query result for the target class name according to the actual effective position of the target class name and the homonym position.
8. The apparatus of claim 7, wherein the location determination module comprises:
the class and position determining unit is used for carrying out class loading by adopting the target class name and determining the actual effective class and the actual effective position of the target class name in the application program according to the class loading result;
and the actual position determining unit is used for acquiring a target class loader to which the target class name belongs and determining the actual effective position of the target class name in the application program by adopting the target class loader if the actual effective position of the target class name in the application program is not obtained according to the loading result.
9. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, causes the one or more processors to implement the method of collision-like detection of an application as claimed in any of claims 1 to 6.
10. A computer readable storage medium having stored thereon a computer program, which when executed by a processor implements a method of collision detection of an application program according to any of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311657756.9A CN117609084A (en) | 2023-12-05 | 2023-12-05 | Class conflict detection method, device and equipment for application program and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311657756.9A CN117609084A (en) | 2023-12-05 | 2023-12-05 | Class conflict detection method, device and equipment for application program and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117609084A true CN117609084A (en) | 2024-02-27 |
Family
ID=89946039
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311657756.9A Pending CN117609084A (en) | 2023-12-05 | 2023-12-05 | Class conflict detection method, device and equipment for application program and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117609084A (en) |
-
2023
- 2023-12-05 CN CN202311657756.9A patent/CN117609084A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106649488B (en) | Method and device for calling multi-data-source interactive interface | |
CN110858172A (en) | Automatic test code generation method and device | |
CN110290135B (en) | Method for unified and standardized processing of complex messages and requested data stream | |
CN111752843A (en) | Method, device, electronic equipment and readable storage medium for determining influence surface | |
CN104320312A (en) | Network application safety test tool and fuzz test case generation method and system | |
CN110598135A (en) | Network request processing method and device, computer readable medium and electronic equipment | |
CN116523457A (en) | Workflow processing method, device, equipment and storage medium based on business process | |
CN112269706A (en) | Interface parameter checking method and device, electronic equipment and computer readable medium | |
CN116881156A (en) | Automatic test method, device, equipment and storage medium | |
CN112860566B (en) | Applet detection method, device, electronic equipment and readable medium | |
CN117520195A (en) | Method, apparatus, device, storage medium and program product for testing interface | |
CN116382640A (en) | Method, device, equipment and storage medium for managing micro-service | |
CN116737535A (en) | Interface test method, device, computer equipment and storage medium | |
CN117609084A (en) | Class conflict detection method, device and equipment for application program and storage medium | |
CN112130860B (en) | JSON object analysis method and device, electronic equipment and storage medium | |
CN114443802A (en) | Interface document processing method and device, electronic equipment and storage medium | |
CN114357331A (en) | Webpage information display method and device, electronic equipment, storage medium and product | |
CN114115908A (en) | Instruction set generation method, program analysis method, device and storage medium | |
CN115687815A (en) | Page information display method, device, equipment and medium | |
CN111400623A (en) | Method and apparatus for searching information | |
CN117407204B (en) | Application program fault positioning method, device, equipment and storage medium | |
CN118170430B (en) | Method, device, equipment and storage medium for processing call link | |
CN117076332B (en) | Test case testing method and device, electronic equipment and storage medium | |
CN115203060B (en) | IAST-based security testing method and device | |
CN117453747A (en) | Data quality detection method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |