CN117389660A - Method and system for detecting jar packet homonymy - Google Patents

Method and system for detecting jar packet homonymy Download PDF

Info

Publication number
CN117389660A
CN117389660A CN202311593796.1A CN202311593796A CN117389660A CN 117389660 A CN117389660 A CN 117389660A CN 202311593796 A CN202311593796 A CN 202311593796A CN 117389660 A CN117389660 A CN 117389660A
Authority
CN
China
Prior art keywords
class
byte code
code file
jar
service
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
Application number
CN202311593796.1A
Other languages
Chinese (zh)
Inventor
王文龙
王茹茹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CITIC Aibank Corp Ltd
Original Assignee
CITIC Aibank Corp Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by CITIC Aibank Corp Ltd filed Critical CITIC Aibank Corp Ltd
Priority to CN202311593796.1A priority Critical patent/CN117389660A/en
Publication of CN117389660A publication Critical patent/CN117389660A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/53Decompilation; Disassembly

Abstract

The invention relates to a method and a system for detecting the same name class of a jar packet, comprising the steps of obtaining a byte code file containing a service in the jar packet; decompiling the byte code file into a source code file to generate a service source code file; extracting classes referenced in a service source code file to generate a first class set; circularly traversing and analyzing all byte code files in the jar package and byte code files in the dependent third-party jar package; screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the depending third-party jar package to generate a second class set; cross-comparing the first class set with the second class set, screening out homonyms referenced by service codes, and generating a homonym list; and configuring a homonym white list according to the homonym list. The invention does not need to rely on a Maven construction tool and does not need to rely on source codes for compiling. And analyzing the byte code file by scanning the jar packet, acquiring a class list with the same name relied on in the project, and solving the problem of jar packet conflict caused by the class with the same name.

Description

Method and system for detecting jar packet homonymy
Technical Field
The invention relates to the technical field of computers, in particular to a method and a system for detecting the same name class of jar packets.
Background
In Java applications, jar packages are a commonly used file format that contains Java classes, resource files, and other related files. However, when there are congruence classes in multiple jar packets, a conflict may occur, resulting in an application that may not function properly. The essential reason for jar packet conflict is that Java applications do not load the correct class due to some factor, resulting in inconsistent behavior with expectations. The reasons can be divided into two categories, one is related to construction, and error jar packets are introduced due to Maven's dependent delivery principle. Another type of run-related, jar packet collision that occurs during run-time is most often caused by the JVM loading into an incorrect class of the same name, since the JVM's class loader defaults that one class can only be loaded once, resulting in the class of the same name not being loaded again. When two same name classes have different methods, the service can be caused to throw java.
To solve the above problem, a common solution is to rely on a maven-shell-plug in plug-in a maven construction tool, which can package the dependency of an item into the final executable jar file of the item, and rename the dependent jar package, which has the advantage of being used for class isolation and reducing the occurrence of dependency conflict. However, the maven-shell-plug in plug-in can rename dependent jar packets only for discovered homonyms during the compilation stage. Since a project may depend on many jar packages, there may also be many homonyms between the jar packages. However, these same name classes are not all directly referenced by the service codes, so great trouble is brought to detecting and scanning the same name class codes.
Disclosure of Invention
In order to solve at least one problem mentioned in the background art, the invention provides a method and a system for detecting the same name class of a jar packet, a Java decompilation tool decompiles a source code from a byte code file to obtain a class referenced by a service code, scans and analyzes the same name class contained in the jar to extract a list of the same name class referenced by the service code, and provides a powerful method for solving the conflict of the jar packet.
In order to achieve the above object, the present invention adopts the technical scheme that:
a method for detecting jar packet homonyms, comprising:
s1, acquiring a byte code file containing a service in a jar packet;
s2, decompiling the byte code file into a source code file to generate a service source code file;
s3, extracting the referenced class in the service source code file to generate a first class set;
s4, circularly traversing and analyzing all byte code files in the jar package and the byte code files in the depending third-party jar package;
s5, screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the dependent third-party jar package to generate a second class set;
s6, cross-comparing the first class set with the second class set, screening out homonyms quoted by service codes, and generating a homonym list;
s7, configuring a homonymy white list according to the homonymy list.
Further, the step S1 further includes: and compiling the source code construction in the git warehouse into jar packets through a CICD pipeline.
Further, the extracting the class referenced in the source code file includes: extracting the class referenced in the source code file through a regular expression.
Further, the method further comprises: and acquiring the homonyms which do not exist in the homonym white list and exist in the homonym list, generating alarm information, sending the alarm information to a user, and displaying the homonym list on a CICD pipeline page.
The invention also relates to a system for detecting the jar packet homonymy, which comprises the following steps:
the first acquisition module is used for acquiring a byte code file containing the service in the jar packet;
the decompilation module is used for decompiling the byte code file into a source code file and generating a service source code file;
the extraction module is used for extracting the referenced classes in the service source code file and generating a first class set;
the traversal analysis module is used for circularly traversing and analyzing all byte code files in the jar package and the byte code files in the dependent third-party jar package;
the screening module is used for screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the depending third-party jar package to generate a second class set;
the comparison module is used for carrying out cross comparison on the first class set and the second class set, screening out homonyms quoted by service codes and generating a homonym list;
and the configuration module is used for configuring the homonym white list according to the homonym list.
The invention also relates to a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, implements the above-mentioned method.
The invention also relates to an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, which processor implements the above-mentioned method when executing the computer program.
The invention also relates to a computer program product comprising a computer program and/or instructions, characterized in that the computer program and/or instructions, when executed by a processor, implement the steps of the above-mentioned method.
The beneficial effects of the invention are as follows:
1. the method can rapidly and accurately detect the homonym class in the jar packet, and avoids the abnormality of the application program caused by the homonym class.
2. The method can automatically generate alarm information, can accurately detect which homonyms are directly referenced by service codes, and is convenient for developers to debug and repair.
3. The method can find out the conflict of the same name class in the development stage and give an alarm notification to the developer in time, thereby reducing the conflict problem of the jar packets of the same name class in the production environment and reducing production faults.
Compared with a Maven-shot-plug in, the method does not need to rely on a Maven construction tool and does not need to rely on source codes for compiling. The byte code file is directly analyzed by scanning jar, and the list of the homonyms relied on in the project can be obtained.
Drawings
FIG. 1 is a flow chart of a method for detecting the same name class of jar packets according to the present invention.
FIG. 2 is a schematic diagram of a system for detecting jar packets of the same name class according to the present invention.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the present application more apparent, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
It should be understood that throughout the description of this application, unless the context clearly requires otherwise, the words "comprise," "comprising," and the like in the description and the claims are to be construed in an inclusive sense rather than an exclusive or exhaustive sense; that is, it is the meaning of "including but not limited to".
It should also be appreciated that the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. Furthermore, in the description of the present application, unless otherwise indicated, the meaning of "a plurality" is two or more.
It should be noted that the terms "S1", "S2", and the like are used for the purpose of describing steps only, and are not intended to be limited to the order or sequence of steps or to limit the present application, but are merely used for convenience in describing the method of the present application and are not to be construed as indicating the sequence of steps. In addition, the technical solutions of the embodiments may be combined with each other, but it is necessary to base that the technical solutions can be realized by those skilled in the art, and when the technical solutions are contradictory or cannot be realized, the combination of the technical solutions should be regarded as not exist and not within the protection scope of the present application.
Java virtual machine (English: javaVirtual Machine, abbreviation: JVM): is a virtual machine capable of executing Java bytecodes, and is implemented as a stack structure machine. The first version of the implementation, originally developed and implemented by Sun microsystems, is part of the Java platform, capable of executing software programs written in the Java language. The Java virtual machine has a perfect hardware architecture, such as a processor, a stack, a register and the like, and also has a corresponding instruction system. The JVM masks information about a specific operating system platform so that Java programs can run unmodified on a variety of platforms by only generating object code (bytecode) that runs on the Java virtual machine. The implementation of the software executed by the Central Processing Unit (CPU) enables the execution of compiled Java program codes (applets and applications). As a virtual machine of a programming language, not just a Java language, but any language can be compiled and run by the JVM as long as the generated compiled file meets the JVM's requirements for loading the compiled file format.
Apache Maven: is a software project management and automatic construction tool which can be used for constructing and managing projects written in Java, C#, ruby, scala and other languages. It contains an object model, a set of criteria, a dependency management system, and plug-in targets and logic for running definitions in the lifecycle stages.
CICD, continuous Integrity, continuous Delivery, consistent Deployment, continuously integrated, continuously delivered, continuously deployed. CI/CD is a method of frequently delivering applications to clients by introducing automation during the application development phase.
The first aspect of the present invention relates to a method for detecting the same name class of jar packets, which is shown in fig. 1 in the step flow, and includes:
s1, acquiring a byte code file containing a service in a jar packet;
specifically, in the embodiment of the present application, before S1, the user compiles the source code construct in the git repository into the executable program jar package through the CICD (continuous integration and continuous deployment) pipeline.
S2, decompiling the byte code file into a source code file to generate a service source code file;
s3, extracting the referenced class in the service source code file to generate a first class set;
specifically, in the embodiment of the application, a class byte code file of a service contained in a jar packet is decompiled into a java source code file, and a class referenced by each java source code file import is extracted through a regular expression to generate a first class set.
S4, circularly traversing and analyzing all byte code files in the jar package and the byte code files in the depending third-party jar package;
s5, screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the dependent third-party jar package to generate a second class set;
specifically, in the embodiment of the application, all class files in the jar package and/or class files in the third-party jar package depending on the lib directory are circularly traversed and analyzed, class classes with the same-name class characteristics are screened out, and a second class set is generated.
S6, cross-comparing the first class set with the second class set, screening out homonyms quoted by service codes, and generating a homonym list;
specifically, in the embodiment of the application, a first class set (i.e., the class referenced by each java source code file import) and a second class set (i.e., the class with the same name screened in S5) are cross-compared, which classes with the same name are directly referenced by the service code import are filtered, a class list with the same name is generated, and the class list with the same name is stored in a database.
S7, configuring a homonymy white list according to the homonymy list.
Specifically, in the embodiment of the present application, in combination with the homonym list generated in S6, a homonym whitelist configuration is newly created. So as to facilitate developers to judge and process the homonyms according to project conditions. Specifically, the screened homonym list is informed to a developer, and the developer is allowed to process the homonym according to own judgment. The method comprises the steps of adding a white list to carry out skip detection or checking the project source code to check and solve the problem of jar packet conflict caused by the same name class.
Another aspect of the present invention also relates to a system for detecting jar packets with the same name, the structure of which is shown in fig. 2, including:
the first acquisition module is used for acquiring a byte code file containing the service in the jar packet;
the decompilation module is used for decompiling the byte code file into a source code file and generating a service source code file;
the extraction module is used for extracting the referenced classes in the service source code file and generating a first class set;
the traversal analysis module is used for circularly traversing and analyzing all byte code files in the jar package and the byte code files in the dependent third-party jar package;
the screening module is used for screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the depending third-party jar package to generate a second class set;
the comparison module is used for carrying out cross comparison on the first class set and the second class set, screening out homonyms quoted by service codes and generating a homonym list;
and the configuration module is used for configuring the homonym white list according to the homonym list.
By using the system, the above-mentioned operation processing method can be executed and the corresponding technical effects can be achieved.
An embodiment of the present invention also provides a computer-readable storage medium capable of implementing all the steps of the timed task monitoring method in the above embodiment, the computer-readable storage medium storing thereon a computer program which, when executed by a processor, implements all the steps of the timed task monitoring method in the above embodiment.
The embodiment of the invention also provides an electronic device for executing the method, which is used as an implementation device of the method, and at least comprises a processor and a memory, wherein the memory is particularly used for storing data and related computer programs required by executing the method, and the data and the programs in the memory are called by the processor to execute all the steps of the implementation method, so that the corresponding technical effects are obtained.
Preferably, the electronic device may comprise a bus architecture, and the bus may comprise any number of interconnected buses and bridges, the buses linking together various circuits, including the one or more processors and memory. The bus may also link together various other circuits such as peripheral devices, voltage regulators, power management circuits, etc., as are well known in the art and, therefore, will not be further described herein. The bus interface provides an interface between the bus and the receiver and transmitter. The receiver and the transmitter may be the same element, i.e. a transceiver, providing a unit for communicating with various other systems over a transmission medium. The processor is responsible for managing the bus and general processing, while the memory may be used to store data used by the processor in performing operations.
Additionally, the electronic device may further include a communication module, an input unit, an audio processor, a display, a power supply, and the like. The processor (or controllers, operational controls) employed may comprise a microprocessor or other processor device and/or logic devices that receives inputs and controls the operation of the various components of the electronic device; the memory may be one or more of a buffer, a flash memory, a hard drive, a removable medium, a volatile memory, a nonvolatile memory, or other suitable means, may store the above-mentioned related data information, may further store a program for executing the related information, and the processor may execute the program stored in the memory to realize information storage or processing, etc.; the input unit is used for providing input to the processor, and can be a key or a touch input device; the power supply is used for providing power for the electronic equipment; the display is used for displaying display objects such as images and characters, and may be, for example, an LCD display. The communication module is a transmitter/receiver that transmits and receives signals via an antenna. The communication module (transmitter/receiver) is coupled to the processor to provide an input signal and to receive an output signal, which may be the same as in the case of a conventional mobile communication terminal. Based on different communication technologies, a plurality of communication modules, such as a cellular network module, a bluetooth module, and/or a wireless local area network module, etc., may be provided in the same electronic device. The communication module (transmitter/receiver) is also coupled to the speaker and microphone via the audio processor to provide audio output via the speaker and to receive audio input from the microphone to implement the usual telecommunications functions. The audio processor may include any suitable buffers, decoders, amplifiers and so forth. In addition, the audio processor is also coupled to the central processor so that sound can be recorded on the host through the microphone and sound stored on the host can be played through the speaker.
It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a system for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks. While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
The foregoing is only a preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions easily contemplated by those skilled in the art within the scope of the present invention should be included in the scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims (8)

1. A method for detecting a jar packet homonymy, comprising:
s1, acquiring a byte code file containing a service in a jar packet;
s2, decompiling the byte code file into a source code file to generate a service source code file;
s3, extracting the referenced class in the service source code file to generate a first class set;
s4, circularly traversing and analyzing all byte code files in the jar package and the byte code files in the depending third-party jar package;
s5, screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the dependent third-party jar package to generate a second class set;
s6, cross-comparing the first class set with the second class set, screening out homonyms quoted by service codes, and generating a homonym list;
s7, configuring a homonymy white list according to the homonymy list.
2. The method of claim 1, wherein S1 is preceded by: and compiling the source code construction in the git warehouse into jar packets through a CICD pipeline.
3. The method of claim 2, wherein the extracting the class referenced in the source code file comprises: extracting the class referenced in the source code file through a regular expression.
4. The method of claim 1, wherein the method further comprises: and acquiring the homonyms which do not exist in the homonym white list and exist in the homonym list, generating alarm information, sending the alarm information to a user, and displaying the homonym list on a CICD pipeline page.
5. A system for detecting a jar packet alike, comprising:
the first acquisition module is used for acquiring a byte code file containing the service in the jar packet;
the decompilation module is used for decompiling the byte code file into a source code file and generating a service source code file;
the extraction module is used for extracting the referenced classes in the service source code file and generating a first class set;
the traversal analysis module is used for circularly traversing and analyzing all byte code files in the jar package and the byte code files in the dependent third-party jar package;
the screening module is used for screening all byte code files in the jar package and classes with the same-name class characteristics in the byte code files in the depending third-party jar package to generate a second class set;
the comparison module is used for carrying out cross comparison on the first class set and the second class set, screening out homonyms quoted by service codes and generating a homonym list;
and the configuration module is used for configuring the homonym white list according to the homonym list.
6. A computer readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when executed by a processor, implements the method of any of claims 1 to 4.
7. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method of any of claims 1 to 4 when executing the computer program.
8. A computer program product comprising a computer program and/or instructions which, when executed by a processor, implement the steps of the method of any one of claims 1 to 4.
CN202311593796.1A 2023-11-27 2023-11-27 Method and system for detecting jar packet homonymy Pending CN117389660A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311593796.1A CN117389660A (en) 2023-11-27 2023-11-27 Method and system for detecting jar packet homonymy

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311593796.1A CN117389660A (en) 2023-11-27 2023-11-27 Method and system for detecting jar packet homonymy

Publications (1)

Publication Number Publication Date
CN117389660A true CN117389660A (en) 2024-01-12

Family

ID=89472093

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311593796.1A Pending CN117389660A (en) 2023-11-27 2023-11-27 Method and system for detecting jar packet homonymy

Country Status (1)

Country Link
CN (1) CN117389660A (en)

Similar Documents

Publication Publication Date Title
CN110083360B (en) Compiling method, device, equipment and storage medium of application program code
CN107832059B (en) Code static analysis method and device based on Makefile
US20080196004A1 (en) Apparatus and method for developing component-based software
CN110727581B (en) Crash positioning method and electronic equipment
CN111158741A (en) Method and device for monitoring change of dependency relationship of business module on third-party class library
CN112882718A (en) Compiling processing method, device, equipment and storage medium
CN110333872B (en) Application processing method, device, equipment and medium
CN114895935A (en) Method and device for flashing vehicle ECU, electronic equipment and storage medium
CN111596951A (en) Method and device for configuring engineering file
CN114356779A (en) Programming language debugging method and device and terminal equipment
CN109284222B (en) Software unit, project testing method, device and equipment in data processing system
CN111352631B (en) Interface compatibility detection method and device
US10606569B2 (en) Declarative configuration elements
CN110334031B (en) Memory allocation code detection method and device, computer equipment and storage medium
CN110990833A (en) SDK safety detection method and related equipment
CN117389660A (en) Method and system for detecting jar packet homonymy
CN106778270B (en) Malicious application detection method and system
US20150033213A1 (en) Compiling method, storage medium and compiling apparatus
CN115809076A (en) ECU software automation integration method and system
CN113721940A (en) Software deployment method and device, electronic equipment and storage medium
CN114253587A (en) Application program updating method and device, electronic equipment and readable storage medium
CN113342600A (en) Method and device for monitoring program dependent plug-in
CN112953721A (en) IPA file analysis method, device, equipment and storage medium
CN113778451A (en) File loading method and device, computer system and computer readable storage medium
CN115168175A (en) Program error solving method, 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