Code problem identification method and device, equipment, storage medium and product
By constructing a syntax analysis tree and a call relationship graph, and combining it with multimodal graph neural network analysis, the problem that traditional code problem identification schemes cannot identify the impact of code changes has been solved, and fast and accurate detection of existing code has been achieved.
Patent Information
- Application Number
- CN202511003548.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-21
- Publication Date
- 2025-11-07
AI Technical Summary
Traditional code problem identification schemes cannot accurately identify the impact of code changes on existing code, nor can they identify the context associated with them.
A syntax analysis tree for the code to be identified is constructed, class details are extracted, and a call relationship graph is built. Multimodal graph neural networks are used for analysis, including a multimodal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer. Code problems are identified, and the identification results are verified by depth-first search or topology sorting detection algorithms.
It enables real-time output of the impact range and potential problems after code changes are committed, significantly improving the detection accuracy and recall rate of existing code, reducing false negatives in complex dependency scenarios, and quickly and accurately identifying code problems.
Smart Images

Figure CN120909901A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of software engineering, and particularly relates to a code problem identification method and device, equipment, a storage medium and a product. BACKGROUND
[0002] A traditional code problem identification scheme can only perform quality problem scanning based on a single code file and cannot identify associated context, so that the influence of code changes on stock code cannot be accurately identified.
[0003] The above content is only used to assist in understanding the technical solutions of the present application and does not represent the acknowledgement of the above content as prior art. SUMMARY
[0004] The main purpose of the present application is to provide a code problem identification method, device, equipment, storage medium and product, which aims to solve the technical problem that the traditional code problem identification scheme cannot accurately identify the influence of code changes on stock code.
[0005] To achieve the above purpose, the present application provides a code problem identification method, which comprises the following steps:
[0006] A syntax analysis tree of to-be-identified code is constructed;
[0007] Class detailed information is extracted from the syntax analysis tree, and a call relationship graph is constructed according to the class detailed information;
[0008] The call relationship graph is analyzed based on a multi-modal graph neural network to identify code problems, wherein the multi-modal graph neural network comprises a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer and an output layer.
[0009] In an embodiment, the step of constructing the call relationship graph according to the class detailed information comprises:
[0010] A class method call relationship is parsed according to the class detailed information, wherein the class method call relationship comprises an internal call relationship, a cross-class call relationship and an interface abstract class call relationship;
[0011] A call relationship graph is constructed based on the class detailed information, the internal call relationship, the cross-class call relationship and the interface abstract class call relationship, wherein the call relationship graph comprises graph nodes and edges, the graph nodes represent classes and methods, and the edges represent call relationships between the graph nodes.
[0012] In an embodiment, the step of analyzing the call relationship graph based on the multi-modal graph neural network to identify code problems comprises:
[0013] inputting the call relationship graph into the multi-modal graph neural network, extracting node features, edge features and global graph features from the call relationship graph through the multi-modal feature fusion layer, and performing cross-modal fusion on the node features, the edge features and the global graph features to obtain multi-modal features;
[0014] performing multi-layer convolution operation on the multi-modal features through the graph neural network to obtain node feature representation;
[0015] performing relationship enhancement on the node feature representation through the relationship perception layer to obtain target node feature representation;
[0016] processing the target node feature representation through the output layer to identify the code problem of the to-be-identified code.
[0017] In an embodiment, after the step of analyzing the call relationship graph based on the multi-modal graph neural network to identify the code problem, the method further comprises:
[0018] when the code problem is a circular dependency problem, performing secondary detection on the call relationship graph according to a depth-first search algorithm or a topological sorting detection algorithm to obtain an actual detection result;
[0019] when the actual detection result is consistent with the result of the code problem, determining a circular dependency path corresponding to the code problem and determining an actual circular dependency path corresponding to the actual detection result;
[0020] determining a path coincidence rate of the circular dependency path and the actual circular dependency path;
[0021] determining whether the path coincidence rate is greater than a preset coincidence rate;
[0022] when the path coincidence rate is greater than or equal to the preset coincidence rate, determining that the code problem is valid, and generating an impact range analysis report for the code problem;
[0023] when the path coincidence rate is less than the preset coincidence rate, performing parameter tuning on the multi-modal graph neural network.
[0024] In an embodiment, the step of generating the impact range analysis report for the code problem comprises:
[0025] performing a graph traversal algorithm to traverse the call relationship graph with the actual circular dependency path as a starting point to obtain a set of associated nodes;
[0026] calculating the dependency strength of each associated node in the set of associated nodes and the actual circular dependency path;
[0027] determine, as a core node, an associated node in the associated node set whose dependency strength index is greater than a preset index;
[0028] construct an influence propagation path graph based on the core node, and generate an influence range analysis report for the code problem according to the influence propagation path graph.
[0029] In an embodiment, the step of calculating the dependency strength of each associated node in the associated node set and the actual circular dependency path includes:
[0030] obtaining calling relationship data of the associated node and nodes in the actual circular dependency path;
[0031] extracting data dependency features between the associated node and the actual circular dependency path;
[0032] analyzing control flow influence features of the associated node on the actual circular dependency path;
[0033] calculating the dependency strength of each associated node in the associated node set and the actual circular dependency path based on the calling relationship data, the data dependency features, and the control flow influence features.
[0034] In addition, to achieve the above object, the present application further provides a code problem identification device, which comprises:
[0035] a construction module configured to construct a syntax analysis tree of a code to be identified;
[0036] an extraction module configured to extract class detailed information from the syntax analysis tree, and construct a calling relationship graph based on the class detailed information;
[0037] an analysis module configured to analyze the calling relationship graph based on a multi-modal graph neural network, and identify a code problem, wherein the multi-modal graph neural network comprises a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer.
[0038] In addition, to achieve the above object, the present application further provides a code problem identification device, which comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program is configured to implement the steps of the code problem identification method as described above.
[0039] In addition, to achieve the above object, the present application further provides a storage medium, which is a computer-readable storage medium, and has a computer program stored thereon, wherein the computer program is executable on a processor to implement the steps of the code problem identification method as described above.
[0040] In addition, to achieve the above object, the present application also provides a computer program product, which comprises a computer program, and the computer program implements the steps of the code problem identification method when executed by a processor.
[0041] The one or more technical solutions provided by the present application have at least the following technical effects:
[0042] The code problem identification method, device, equipment, storage medium and product provided by the present application construct a syntax analysis tree of the code to be identified; extract class detailed information from the syntax analysis tree, and construct a call relationship graph based on the class detailed information; analyze the call relationship graph based on a multi-modal graph neural network, and identify a code problem, wherein the multi-modal graph neural network comprises a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer and an output layer. The technical problem that the traditional code problem identification scheme cannot accurately identify the influence of code changes on stock code is solved. Compared with the prior art, the present application can output the influence range and potential problems in real time after the code changes are submitted through the end-to-end link of “syntax analysis tree-class detailed information-call relationship graph-multi-modal graph neural network”, which significantly improves the detection accuracy and recall rate of the impact on stock code. Moreover, the multi-modal feature fusion layer is designed to fuse three modalities of structure, semantics and statistics, the graph neural network layer performs multi-hop information propagation on the call graph, the ripple effect of a local modification is globally perceived, the relationship perception layer is used to explicitly model the call types and loop paths, false negative relationships in a complex dependency scenario are further reduced, and finally the output layer is used to output the corresponding code problem, so that the influence of the code to be identified on stock code can be quickly and accurately identified. BRIEF DESCRIPTION OF DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and serve to explain the principles of the present application together with the specification.
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0045] Figure 1 The flowchart provided for the code problem identification method embodiment one of the present application;
[0046] Figure 2 The class related information diagram provided for the code problem identification method embodiment one of the present application;
[0047] Figure 3 A class method call relationship diagram is provided for the code problem identification method embodiment one of the present application.
[0048] Figure 4 A flow diagram is provided for the code problem identification method embodiment two of the present application.
[0049] Figure 5 A topological sorting algorithm diagram is provided for the code problem identification method embodiment two of the present application.
[0050] Figure 6 A module structure diagram of the code problem identification device of the present application embodiment is provided.
[0051] Figure 7 A device structure diagram of the hardware running environment involved in the code problem identification method in the present application embodiment is provided.
[0052] The object implementation, functional features and advantages of the present application will be further described with reference to the accompanying drawings in conjunction with the embodiments. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application, and are not used to limit the present application.
[0054] In order to better understand the technical solutions of the present application, the specific embodiments will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0055] The main solution of the present application embodiment is to construct a syntax analysis tree of the code to be identified; extract class detailed information from the syntax analysis tree, and construct a call relationship graph according to the class detailed information; based on a multi-modal graph neural network, analyze the call relationship graph, and identify the code problem, wherein the multi-modal graph neural network includes a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer and an output layer.
[0056] It can be known from the above embodiments that the code problem identification method, device, equipment, storage medium and product provided by the application, by constructing a syntax analysis tree of the to-be-identified code, extracting class detailed information from the syntax analysis tree, and constructing a call relationship graph based on the class detailed information, the call relationship graph is analyzed based on a multi-modal graph neural network to identify code problems, wherein the multi-modal graph neural network includes a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer. The technical problem that the traditional code problem identification scheme cannot accurately identify the impact of code changes on the stock code is solved. Compared with the prior art, the end-to-end link of "syntax analysis tree-class detailed information-call relationship graph-multi-modal graph neural network" is used in the application, and the impact range and potential problems can be output in real time after the code changes are submitted, which significantly improves the detection accuracy and recall rate of the impact on the stock code. Moreover, the multi-modal feature fusion layer is designed to fuse the structure, semantics, and statistics of three modalities. The graph neural network layer performs multi-hop information propagation on the call graph, so that the ripple effect of a local modification is globally perceived. The relationship perception layer explicitly models the call types and loop paths to further reduce false negative relationships in complex dependency scenarios. Finally, the output layer outputs the corresponding code problems, thereby quickly and accurately identifying the impact of the to-be-identified code on the stock code.
[0057] It should be noted that the execution subject of the present embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a code problem identification device, etc. capable of realizing the above functions. The present embodiment and the following embodiments will be described below taking the code problem identification device as an example.
[0058] Based on this, the code problem identification method provided by the present embodiment is described with reference to Figure 1 , Figure 1 The flowchart of the first embodiment of the code problem identification method of the present application is shown in the figure.
[0059] In the present embodiment, the code problem identification method includes steps S10-S30:
[0060] Step S10, constructing a syntax analysis tree of the to-be-identified code;
[0061] It should be noted that the syntax analysis tree refers to converting the to-be-identified code into a hierarchical and structured "tree-shaped" intermediate representation, so that subsequent analysis (such as dependency extraction and problem detection) can be based on clear syntax units, rather than directly operating on the original text. The AST syntax analysis tree of the to-be-identified code can be constructed with the aid of a code syntax analysis tool. Specifically, the to-be-identified code can be subjected to lexical analysis: scanning the source code character stream and splitting it into individual "lexical units" (Token), such as keywords, identifiers, operators, etc.; then, the to-be-identified code is subjected to syntax analysis, such as according to the syntax rules (usually context-free grammar) of the programming language, to organize the Token sequence into a syntax analysis tree (Parse Tree) or an abstract syntax tree (AST). The root node in the syntax analysis tree corresponds to the entire source code file (or function, class); the internal node corresponds to the syntax structure (such as if statement, for loop, method call); and the leaf node corresponds to the Token itself.
[0062] Step S20: extracting class detailed information from the syntax analysis tree, and constructing a call relationship graph based on the class detailed information;
[0063] It should be noted that the key information (i.e., class detailed information) of each class can be extracted from the syntax analysis tree, such as Figure 2 As shown in the table, the class detailed information includes class name, package name, application to which the class belongs, detailed annotation information, variable definition, method name, parameter list, and start and end line numbers of each code element.
[0064] In a feasible implementation, the step of constructing a call relationship graph based on the class detailed information includes: parsing class method call relationships based on the class detailed information, wherein the class method call relationships include internal call relationships, cross-class call relationships, and interface abstract class call relationships; and constructing a call relationship graph based on the class detailed information, the internal call relationships, the cross-class call relationships, and the interface abstract class call relationships, wherein the call relationship graph includes graph nodes and edges, the graph nodes represent classes and methods, and the edges represent call relationships between the graph nodes.
[0065] It should be noted that, as Figure 3As shown, the class method call relationship includes internal method call relationship, cross-class method call relationship, interface / abstract class call relationship, wherein the internal method call (i.e. internal call relationship) refers to the call of a method to other methods in the same class; the cross-class method call (i.e. cross-class call relationship) refers to the call of a method of another class through a temporary variable reference, covering the interaction between different classes, including direct call, Bean method call, etc.; the interface / abstract class call (i.e. interface / abstract class call relationship) refers to the call of a method defined by an interface or an abstract class.
[0066] In a specific implementation, a directed graph is constructed according to the method call relationship, and the element of each graph node is "package name + class name + method name + method parameter". Special processing is required for recursive calls in the process of constructing the graph to prevent the occurrence of a dead loop in the construction process. The following pseudo code is used as an example to simply describe the process of constructing the call relationship graph:
[0067]
[0068]
[0069] In a specific implementation, the steps of generating the call relationship graph according to the class method call relationship are as follows:
[0070] 1. Graph data preparation:
[0071] Node information preparation: package, class, method, and parameter. The nodes obtained by the example code are as follows:
[0072]
[0073] Edge information: call relationship and row number
[0074] The example code scanning result can obtain the following three edges:
[0075] PackageA.ClassA.methodA---->PackageB.ClassB.methodB
[0076] PackageB.ClassB.methodB---->PackageC.ClassC.methodC
[0077] PackageB.ClassB.methodB---->PackageD.ClassD.methodD
[0078] 2. Construction of a directed graph
[0079] Node creation: create a node for each class and method, and record its attributes; edge connection: add edges to each node according to the extracted call relationship, pointing to other nodes.
[0080] 3. Data storage: store the constructed graph in a graph database.
[0081] It can be understood that building a call relationship graph based on the code to be identified can change from "human readable" to "machine analyzable", so that the code is no longer a simple string, but structured data that can be accurately parsed, checked and modified by a program, and problem detection is achieved through graph algorithms and rule engines.
[0082] In specific implementation, code problems can be identified through graph algorithms and rule engines. For the "circular dependency problem (example: ClassA->ClassB->ClassC->ClassA)", the identification steps are: model the call relationship as a directed graph, node = class, edge = call relationship; use depth-first search or topological sorting to detect loops in the graph; output all node paths involved in the loop and mark them as circular dependencies. For the "obsolete API call problem", the class method ClassB.methodB annotated with @Deprecated can be identified by scanning the class basic information, and then the class method ClassA.methodA that calls ClassB.methodB can be identified through the class method call relationship, and marked as calling obsolete API. For the "long transaction risk identification problem (i.e. transaction process contains external system calls, middleware calls, etc. long time-consuming operations)", all transactional methods can be scanned and marked, and then the call relationship contained in the transactional method can be constructed according to the upstream and downstream call relationship. Then use depth-first search to traverse all child nodes in the graph to check whether it contains external system calls and middleware calls. If external system calls or middleware calls are found, mark the abnormal link to identify long transaction risks.
[0083] Step S30, based on the multi-modal graph neural network, analyzing the call relationship graph to identify code problems, wherein the multi-modal graph neural network includes a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer.
[0084] It should be noted that the identified code problems can be some circular dependency problems, outdated API call problems, long transaction risk identification problems, and unused code identification problems. Among them, circular dependency refers to the mutual dependence of two or more modules, classes or components, forming a closed loop, which is difficult to manage and maintain; the problem of calling outdated API refers to the use of an API that has been marked as deprecated in the code; the problem of long transaction risk identification refers to the existence of an unusually long transaction processing time in the software system, which may negatively affect system performance and stability; the problem of unused code identification refers to the existence of methods, functions, variables, etc. in the code that are not called or used, increasing the redundancy and complexity of the code.
[0085] It should be noted that the role of the multi-modal feature fusion layer is to extract different types of features from the call relationship graph, including node features, edge features, and global graph features. These features represent the nodes in the graph, the connection between nodes, and the structure information of the entire graph. Through the multi-modal feature fusion layer, these different types of features can be integrated for subsequent processing and analysis. For example, the role of the MFFR layer is to significantly enhance the distinction between features from different modalities by introducing the first MFFR layer, and the MFFR layer mainly focuses on reconstructing the feature space to reveal more independent and distinct features.
[0086] It should be noted that the graph neural network layer performs multi-layer convolution operations on the extracted multi-modal features to obtain node feature representations. This process involves aggregating and updating the attributes of nodes and their neighbors to capture the complex relationships and dependencies between nodes. Through multi-layer convolution, more abstract and advanced node feature representations can be learned, providing a foundation for subsequent relationship enhancement and problem identification.
[0087] It should be noted that the relationship-aware layer enhances the relationship of node feature representations to obtain target node feature representations. The purpose of this layer is to further consider the semantic relationship between nodes based on node features, and to strengthen these relationships through a relationship-aware mechanism, thereby obtaining more rich and accurate node representations. This helps to identify nodes related to specific code problems, such as circular dependencies, outdated API calls, etc.
[0088] It should be noted that the output layer processes the target node feature representations to ultimately identify the code problems of the code to be identified. This layer usually involves classification or regression tasks, and according to the node feature representation, it predicts whether the node is related to a specific code problem. The design of the output layer needs to consider the diversity and complexity of the problem to achieve accurate code problem identification.
[0089] In an implementable embodiment, the step of analyzing the call relationship graph based on the multi-modal graph neural network to identify the code problem comprises: inputting the call relationship graph into the multi-modal graph neural network, extracting node features, edge features and global graph features from the call relationship graph through the multi-modal feature fusion layer, and performing cross-modal fusion on the node features, the edge features and the global graph features to obtain multi-modal features; performing multi-layer convolution operation on the multi-modal features through the graph neural network to obtain node feature representation; performing relationship enhancement on the node feature representation through the relationship perception layer to obtain target node feature representation; and processing the target node feature representation through the output layer to identify the code problem of the to-be-identified code.
[0090] It should be noted that the node features (Node Features) generally include semantic information of code snippets, structural information of code, etc. For example, a function node may contain information such as function name, parameter list, return type, etc. The edge features (Edge Features) describe the relationship between nodes, such as function call relationship, data dependency relationship, etc. The edge features may include the frequency of calling, the context information of calling, etc. The global graph features (Global Graph Features) are features extracted from the entire call relationship graph, such as the topological structure of the graph, the distribution of nodes, etc. These features can help the model understand the structure and organization of the entire code. Cross-modal fusion (Cross-Modal Fusion) fuses node features, edge features and global graph features to obtain multi-modal features. This fusion method can make full use of information of different modalities to improve the model's understanding of the call relationship graph.
[0091] It should be noted that the call relationship graph G=(V,E), where V represents the node set in the graph, which can be a function, a class, a file, etc. The basic building blocks of code, E represents the edge set in the graph, which represents the calling relationship between nodes, and each edge is directional, indicating the flow direction of the call. Each edge E also has call type information, which can be static call, dynamic call or callback. These call types provide additional information about how the call occurs, which is very important for understanding the behavior of the code and identifying potential problems.
[0092] It should be noted that the multi-modal feature fusion: extracting node features, edge features and global graph features from the call relationship graph, and fusing these features across modalities to obtain a comprehensive multi-modal feature representation. Graph neural network layer: using graph neural network to perform multi-layer convolution operation on multi-modal features to obtain node feature representation. This process involves aggregating and updating the attributes of nodes and their neighbors to capture the complex relationships and dependencies between nodes. Relationship awareness layer: enhancing the node feature representation to obtain the target node feature representation. This layer further considers the semantic relationships between nodes and strengthens these relationships through a relationship awareness mechanism to obtain a more rich and accurate node representation. Output layer: processing the target node feature representation to identify the code problem of the to-be-identified code. This layer usually involves classification or regression tasks, and predicts whether the node is related to a specific code problem based on the node feature representation.
[0093] The embodiment constructs a syntax analysis tree of the to-be-identified code, extracts class detailed information from the syntax analysis tree, and constructs a call relationship graph based on the class detailed information. The call relationship graph is analyzed based on a multi-modal graph neural network to identify a code problem, wherein the multi-modal graph neural network includes a multi-modal feature fusion layer, a graph neural network layer, a relationship awareness layer, and an output layer. The technical problem that the traditional code problem identification scheme cannot accurately identify the impact of code changes on the inventory code is solved. Compared with the prior art, the present application can output the impact range and potential problems in real time after the code changes are submitted through the end-to-end link of "syntax analysis tree-class detailed information-call relationship graph-multi-modal graph neural network", which significantly improves the detection accuracy and recall rate of the impact on the inventory code. Moreover, the multi-modal feature fusion layer is designed to fuse the structure, semantics and statistics of three modalities. The graph neural network layer performs multi-hop information propagation on the call graph, so that the ripple effect of a local modification is globally perceived. The relationship awareness layer explicitly models the call types and loop paths to further reduce false negative relationships in complex dependency scenarios. Finally, the output layer outputs the corresponding code problem, thereby quickly and accurately identifying the impact of the to-be-identified code on the inventory code.
[0094] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as the above first embodiment can be referred to the above introduction, and will not be described in detail. On this basis, please refer to Figure 4 , after step S30, further comprising steps S40-S90:
[0095] In step S40, when the code problem is a circular dependency problem, the call relationship graph is detected again based on a depth-first search algorithm or a topological sorting detection algorithm to obtain an actual detection result.
[0096] It should be noted that after analyzing the call relationship graph using the multi-modal graph neural network, the system identifies possible code problems such as circular dependencies. In order to verify the accuracy of these identification results, the system needs to perform secondary detection. This is usually done by applying a depth-first search (DFS) algorithm or a topological sorting detection algorithm, which can effectively identify circular dependency paths in the graph.
[0097] In a specific implementation, the secondary detection of the call relationship graph according to the depth-first search algorithm or the topological sorting detection algorithm, the identification step is: modeling the call relationship as a directed graph, node = class, edge = call relationship; using depth-first search or topological sorting to detect loops in the graph; output all the node paths involved in the loop and mark them as circular dependencies. Specifically, the topological sorting algorithm: 1. First, count the in-degree of all nodes, delete nodes with in-degree 0, and then reduce the in-degree of the nodes pointed to by this node by 1; 2. Repeat the above operation until there are no nodes with in-degree 0, but there are still nodes, which means there is a loop. For example: Figure 5 Step 1: Find node A with in-degree 0, delete A and the edges pointed to by A, and repeat the process of finding nodes with in-degree 0. It is found that there are no nodes, and there are still nodes in the graph, which proves that there is a loop in the graph. Specifically, the depth-first search algorithm: by starting from a certain node, perform a depth-first traversal. In the traversal process, if a node that has been visited is encountered and this node is not the node visited in the previous step, then there is a loop. For example, the depth search link A->C->D->E->C, when processing the neighbor C of E, it is found that C is in the process of being visited, and it is determined that there is a loop. Figure 1
[0098] Step S50, when the actual detection result is consistent with the result of the code problem, determining the circular dependency path corresponding to the code problem, and determining the actual circular dependency path corresponding to the actual detection result;
[0099] It should be noted that when the path coincidence rate is greater than or equal to the preset coincidence rate, it means that the code problem (such as circular dependency) identified by the multi-modal graph neural network is largely consistent with the problem actually detected, and in this case, the code problem identified by the multi-modal graph neural network can be considered to be effective.
[0100] Step S60, determining the path coincidence rate of the circular dependency path and the actual circular dependency path;
[0101] In a specific implementation, a multi-level evaluation system can be constructed to calculate the path coincidence rate of the circular dependency path and the actual circular dependency path, such as calculating the path coincidence rate from node set similarity, path structure similarity, and call context matching degree.
[0102] In a specific implementation, the node set similarity can be used to measure the degree of overlap of the node set in the predicted path and the actual path. Specifically, weight allocation can be made based on static weights and dynamic weights. For static weights, determination can be made based on node types, such as higher weights for interface / abstract classes (key nodes) and lower weights for ordinary classes. For dynamic weights, determination can be made based on runtime features, such as node call frequency data coupling degree and control flow criticality. The calculation formula of the node set similarity is as follows:
[0103]
[0104] In the formula, P represents the node set of the circular dependency path, T represents the node set of the actual circular dependency path, w(n) represents the node weight (including static weight and dynamic weight), (P∩T) represents the intersection of P and T, and (P∪T) represents the union of P and T.
[0105] It should be noted that the path structure similarity is used to measure the topological structure consistency (order, direction, loop continuity) of the predicted path and the actual path. The call context matching degree measures whether the data flow, control flow and runtime behavior between nodes match. Specifically, the call context matching degree can be determined based on data dependency matching degree, control flow matching degree and timing feature matching degree.
[0106] In a specific implementation, for the data dependency matching degree, the data dependency matching degree can be calculated by checking whether the two paths access the same variable, and the calculation formula of the data dependency matching degree is as follows:
[0107]
[0108] In a specific implementation, for the control flow matching degree, it can be judged whether the exception handling and conditional branching are consistent. If the two paths throw / catch exceptions at the same position, the score is added, and the calculation formula of the control flow matching degree is as follows:
[0109]
[0110] In a specific implementation, for the timing feature matching degree, the call order and concurrency conflict can be checked for consistency, such as checking whether the same method is called at a similar time point, and the calculation formula of the timing feature matching degree is as follows:
[0111]
[0112] Step S70, judging whether the path coincidence rate is greater than a preset coincidence rate;
[0113] It should be noted that the preset coincidence rate can be dynamically adjusted according to the loop complexity, for example, a simple loop sets a higher preset coincidence rate, and a complex loop can set a lower preset coincidence rate.
[0114] Step S80, when the path coincidence rate is greater than or equal to the preset coincidence rate, it is determined that the code problem is valid, and an impact range analysis report for the code problem is generated.
[0115] In a feasible implementation, the step of generating an impact range analysis report for the code problem includes: performing a graph traversal algorithm, taking the actual circular dependency path as the starting point, traversing the call relationship graph to obtain a set of associated nodes; calculating the dependency strength of each associated node in the set of associated nodes and the actual circular dependency path; determining the associated nodes in the set of associated nodes whose dependency strength index is greater than a preset index as core nodes; based on the core nodes, constructing an influence propagation path graph, and generating an impact range analysis report for the code problem according to the influence propagation path graph.
[0116] It should be noted that the graph traversal algorithm (such as depth-first search or breadth-first search) is used to start from the starting point of the actual circular dependency path and traverse the entire call relationship graph, which can identify all nodes directly or indirectly related to the circular dependency path, forming a set of associated nodes. For each node in the set of associated nodes, the dependency strength between it and the actual circular dependency path is calculated, which can be based on various factors such as call frequency, data dependency, control flow influence, etc., to quantify the degree of relationship between the node and the circular dependency path. Nodes with a dependency strength index greater than a preset threshold are determined as core nodes, which represent the most closely related part of the circular dependency problem, and they may be the key to solving the problem. An influence propagation path graph can be constructed based on the core nodes (the graph shows how the core nodes affect other parts of the code through the call relationship). Finally, an impact range analysis report is generated according to the influence propagation path graph, which may include a list of affected modules, classes, functions, and their dependency descriptions with the core nodes, helping developers understand the impact of the problem and develop appropriate solutions.
[0117] In an implementation, the step of calculating the dependency strength of each associated node in the associated node set and the actual circular dependency path comprises: obtaining calling relationship data of the associated node and nodes in the actual circular dependency path; extracting data dependency features between the associated node and the actual circular dependency path; analyzing control flow influence features of the associated node on the actual circular dependency path; and calculating the dependency strength of each associated node in the associated node set and the actual circular dependency path based on the calling relationship data, the data dependency features, and the control flow influence features.
[0118] It should be noted that the calling relationship data includes function calls, method calls, or inheritance relationships between classes, etc. These data can come from code analysis tools, static code scanning, or runtime monitoring data. The data dependency features refer to the dependency relationship between two nodes in data exchange and use, for example, a function can use the output of another function as input. These features can be extracted by analyzing variable passing, parameter passing, and return value in the code. The control flow influence features involve the dependency relationship on the code execution path, that is, how the execution of one node affects the execution of another node. This includes conditional statements (such as if-else), loop statements (such as for, while), and exception handling, etc., which can affect the execution flow and dependency relationship of the code.
[0119] In a specific implementation, the calculation of dependency strength adopts a multi-dimensional weighted evaluation model, which is completed through the following steps: first, based on static code analysis tools (such as Soot, Checkstyle), call relationship data is extracted, including direct function call frequency, class inheritance depth, interface implementation relationship and other structured indicators, and at the same time, combined with runtime call link data collected by a distributed tracking system (such as SkyWalking, Zipkin), a weight coefficient of 1.2-1.5 times is given to remote calls across services / modules; second, through a data flow analysis engine, a variable definition-use chain is constructed to quantitatively analyze data dependency characteristics such as parameter passing, return value dependency and shared variable access, and especially for bidirectional data dependency (such as A→B and B→A variable interaction), a strength coefficient of 30% is added; at the control flow analysis level, program dependency graph (PDG) and control flow graph (CFG) modeling techniques are used to accurately analyze the mutual influence degree of conditional branches, loop structures and exception handling blocks, and nodes in the critical execution path (such as method calls in high-frequency exception capture blocks) are exponentially weighted by 1 / (path branch number) to obtain control flow influence characteristics. Finally, the dependency strength value is normalized by min-max processing, and is weighted and fused according to the proportions of 50% call relationship weight, 30% data dependency weight and 20% control flow weight, wherein runtime indicators such as fuse status and call latency are additionally introduced for microservice architecture to dynamically correct (±15% amplitude). The model continuously optimizes feature weights by integrating the XGBoost algorithm, and uses a historical reconstruction case library for adversarial training, so that the F1-score of the strength evaluation reaches more than 92%, and at the same time, developers can customize weight strategies to adapt to different architecture styles (such as reducing cross-service call weight for monolithic applications and increasing data flow feature weight for event-driven systems). The dependency strength is finally presented in the form of a standardized score of 0-1, and high-strength dependencies (>0.8), moderate dependencies (0.5-0.8) and weak dependencies (<0.5) are automatically labeled, providing quantitative decision-making basis for architecture governance.
[0120] Step S90, when the path coincidence rate is less than the preset coincidence rate, the multi-modal graph neural network is parameter tuned.
[0121] In a specific implementation, the parameter tuning strategy includes feature fusion layer tuning, graph neural network improvement, and relationship perception layer enhancement. Specifically, for "feature fusion layer tuning", the sensitivity to call relationship features can be enhanced by adjusting the attention weight of multi-modal features; for "graph neural network layer improvement", a reconstructed message passing mechanism can be set to improve the ability to capture loop patterns; for "relationship perception layer enhancement", special reinforcement can be performed on misjudged relationship types (such as interface implementation vs. ordinary call).
[0122] The embodiment determines the circular dependency path corresponding to the code problem and determines the actual circular dependency path corresponding to the actual detection result when the actual detection result is consistent with the result of the code problem, determines the path coincidence rate of the circular dependency path and the actual circular dependency path, determines whether the path coincidence rate is greater than a preset coincidence rate, determines that the code problem is valid and generates an impact range analysis report for the code problem when the path coincidence rate is greater than or equal to the preset coincidence rate, and performs parameter tuning on the multi-modal graph neural network when the path coincidence rate is less than the preset coincidence rate. The accuracy of the circular dependency problem identified by the multi-modal graph neural network is verified by performing secondary detection on the call relationship graph by using the depth-first search algorithm or the topological sorting detection algorithm to obtain the actual detection result. When the actual detection result is consistent with the result of the code problem, the circular dependency path and the actual circular dependency path are determined, the path coincidence rate is calculated, and it is determined whether the path coincidence rate is greater than the preset coincidence rate. This process not only effectively verifies the validity of the code problem, but also significantly improves the accuracy of problem identification. When the path coincidence rate is greater than or equal to the preset coincidence rate, it is determined that the code problem is valid, and an impact range analysis report for the code problem is generated, which helps developers quickly understand the impact range and potential risks of the problem, so as to take corresponding solving measures. In addition, when the path coincidence rate is less than the preset coincidence rate, the multi-modal graph neural network is parameter tuned to improve the recognition ability of the model, so as to realize continuous optimization and iterative improvement of the model.
[0123] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the code problem identification method of the present application. More forms of simple transformation based on this technical concept are within the protection scope of the present application.
[0124] The present application also provides a code problem identification device, please refer to Figure 6 , the code problem identification device comprises:
[0125] The construction module 10 is configured to construct a syntax analysis tree of the code to be identified.
[0126] The extraction module 20 is configured to extract class detailed information from the syntax analysis tree and construct a call relationship graph according to the class detailed information.
[0127] The analysis module 30 is configured to analyze the call relationship graph based on a multi-modal graph neural network to identify a code problem, wherein the multi-modal graph neural network comprises a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer.
[0128] The code problem identification device provided in the present application adopts the code problem identification method in the above embodiments, and can solve the technical problem of code problem identification. Compared with the prior art, the code problem identification device provided in the present application has the same beneficial effects as the code problem identification method provided in the above embodiments, and other technical features in the code problem identification device are the same as the features disclosed in the above embodiments, which will not be repeated here.
[0129] The present application provides a code problem identification device, which comprises at least one processor and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the code problem identification method in the above embodiment one.
[0130] Reference will be made to the following description of the embodiments of the present application, taken in conjunction with the accompanying drawings, in which Figure 7 which shows a structural diagram of a code problem identification device suitable for implementing the embodiments of the present application. The code problem identification device in the embodiments of the present application can include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 7 The code problem identification device shown is only an example, and should not bring any limitation to the functions and use range of the embodiments of the present application.
[0131] As Figure 7As shown, the code problem identification device can include a processing apparatus 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to programs stored in a read-only memory 1002 or loaded from a storage apparatus 1003 into a random access memory 1004. Various programs and data required for the code problem identification device to operate are also stored in the random access memory 1004. The processing apparatus 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other by a bus 1005. An input / output interface 1006 is also connected to the bus. Generally, the following systems can be connected to the input / output interface 1006: input apparatuses 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output apparatuses 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; the storage apparatus 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication apparatus 1009. The communication apparatus 1009 can allow the code problem identification device to communicate with other devices wirelessly or by wire to exchange data. Although the code problem identification device with various systems is shown in the figure, it should be understood that all the shown systems are not required to be implemented or possessed. More or fewer systems can be alternatively implemented or possessed.
[0132] In particular, according to embodiments of the present disclosure, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network by a communication apparatus, or installed from the storage apparatus 1003, or installed from the read-only memory 1002. When the computer program is executed by the processing apparatus 1001, the above-mentioned functions defined in the methods of embodiments of the present disclosure are performed.
[0133] The code problem identification device provided by the present disclosure adopts the code problem identification method in the above-mentioned embodiments, and can solve the technical problem that the conventional code problem identification scheme cannot accurately identify the influence of code changes on stock code. Compared with the prior art, the code problem identification device provided by the present disclosure has the same beneficial effects as the code problem identification method provided by the above-mentioned embodiments, and other technical features in the code problem identification device are the same as the features disclosed in the previous embodiment method, which will not be repeated here.
[0134] It should be understood that various parts of the present application can be realized with hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0135] The above description is merely that of a specific implementation of the present application, and the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, and all such changes or replacements should be encompassed within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0136] The present application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e., a computer program) for performing the code problem identification method in the above embodiments.
[0137] The computer readable storage medium provided by the present application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system or device, or any combination thereof. More specific examples of the computer readable storage medium can include, but are not limited to, an electric connection having one or more conductive wires, a portable computer disk, 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 disk read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present embodiment, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer readable storage medium can be transmitted by any suitable medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency), etc., or any suitable combination thereof.
[0138] The above computer readable storage medium can be contained in the code problem identification device; or can exist separately without being assembled into the code problem identification device.
[0139] The computer readable storage medium described above carries one or more programs, when the one or more programs are executed by the code problem identification device, cause the code problem identification device to: construct a syntax analysis tree of the code to be identified; extract class details from the syntax analysis tree, and construct a call relationship graph based on the class details; analyze the call relationship graph based on a multi-modal graph neural network to identify the code problem, wherein the multi-modal graph neural network comprises a node-level encoder, an edge-level encoder, a graph-level encoder, a cross-modal fusion layer, a graph convolution layer, a readout layer, and a code problem classifier.
[0140] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0141] The computer program instructions can also be loaded onto a computer or other programmable information processing apparatus to cause a series of operations to be performed on the computer or other programmable information processing apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable information processing apparatus implement the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0142] The modules described in the embodiments of the present application can be implemented in the form of software or in the form of hardware. In some cases, the names of the modules do not constitute a limitation on the modules themselves.
[0143] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e., a computer program) for executing the above-mentioned code problem identification method, and can solve the technical problem that the conventional code problem identification scheme cannot accurately identify the influence of code changes on stock code. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the code problem identification method provided by the above-mentioned embodiments, and will not be described here.
[0144] The present application also provides a computer program product comprising a computer program, which, when executed by a processor, implements the steps of the code problem identification method as described above.
[0145] The computer program product provided by the present application can solve the technical problem that the conventional code problem identification scheme cannot accurately identify the influence of code changes on stock code. Compared with the prior art, the computer program product provided by the present application has the same beneficial effects as the code problem identification method provided by the above-mentioned embodiments, and will not be described here.
[0146] The above only describes some embodiments of the present application, and does not limit the patent scope of the present application. Any equivalent structural transformation, direct / indirect application in other related technical fields based on the technical concept of the present application, and the content of the present application specification and drawings are included in the patent protection scope of the present application.
Claims
1. A code problem identification method characterized by, The code problem identification method comprises: constructing a syntax analysis tree of the code to be identified; extracting class detailed information from the syntax analysis tree and constructing a call relationship graph based on the class detailed information; analyzing the call relationship graph based on a multi-modal graph neural network to identify a code problem, wherein the multi-modal graph neural network comprises a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer.
2. The code problem identification method of claim 1, wherein The step of constructing a call relationship graph based on the class detailed information comprises: parsing class method call relationships from the class detailed information, wherein the class method call relationships comprise internal call relationships, cross-class call relationships, and interface abstract class call relationships; constructing a call relationship graph based on the class detailed information, the internal call relationships, the cross-class call relationships, and the interface abstract class call relationships, wherein the call relationship graph comprises graph nodes and edges, the graph nodes represent classes and methods, and the edges represent call relationships between the graph nodes.
3. The code problem identification method of claim 1, wherein The step of analyzing the call relationship graph based on the multi-modal graph neural network to identify a code problem comprises: inputting the call relationship graph into the multi-modal graph neural network, extracting node features, edge features, and global graph features from the call relationship graph through the multi-modal feature fusion layer, and performing cross-modal fusion on the node features, the edge features, and the global graph features to obtain multi-modal features; performing multi-layer convolution operations on the multi-modal features through the graph neural network to obtain node feature representations; performing relationship enhancement on the node feature representations through the relationship perception layer to obtain target node feature representations; processing the target node feature representations through the output layer to identify a code problem of the code to be identified.
4. The code problem identification method of claim 1, wherein After the step of analyzing the call relationship graph based on the multi-modal graph neural network to identify a code problem, the method further comprises: when the code problem is a circular dependency problem, performing secondary detection on the call relationship graph based on a depth-first search algorithm or a topological sorting detection algorithm to obtain an actual detection result; when the actual detection result is consistent with the result of the code problem, determining a circular dependency path corresponding to the code problem and an actual circular dependency path corresponding to the actual detection result; determining a path overlap rate of the circular dependency path and the actual circular dependency path; determining whether the path overlap rate is greater than a preset overlap rate; when the path overlap rate is greater than or equal to the preset overlap rate, determining that the code problem is valid and generating an impact range analysis report for the code problem; when the path overlap rate is less than the preset overlap rate, performing parameter tuning on the multi-modal graph neural network.
5. The code problem identification method of claim 4, wherein The step of generating an impact range analysis report for the code problem comprises: performing a graph traversal algorithm to traverse the call relationship graph from the actual circular dependency path as a starting point to obtain a set of associated nodes; calculating dependency strengths of the associated nodes in the set of associated nodes and the actual circular dependency path; and Determine the associated nodes in the associated node set whose dependency strength indicators are greater than a preset indicator as core nodes; Based on the core nodes, construct an influence propagation path graph, and generate an influence range analysis report for the code problem according to the influence propagation path graph.
6. The code problem identification method of claim 5, wherein The step of calculating the dependency strength of each associated node in the associated node set and the actual circular dependency path includes: Obtain the calling relationship data of the associated node and the nodes in the actual circular dependency path; Extract the data dependency features between the associated node and the actual circular dependency path; Analyze the control flow influence features of the associated node on the actual circular dependency path; Based on the calling relationship data, the data dependency features, and the control flow influence features, calculate the dependency strength of each associated node in the associated node set and the actual circular dependency path.
7. A code problem identification apparatus characterized by comprising: The code problem identification device includes: A construction module for constructing a syntax analysis tree of the code to be identified; An extraction module for extracting class detailed information from the syntax analysis tree and constructing a calling relationship graph based on the class detailed information; An analysis module for analyzing the calling relationship graph based on a multi-modal graph neural network to identify code problems, wherein the multi-modal graph neural network includes a multi-modal feature fusion layer, a graph neural network layer, a relationship perception layer, and an output layer.
8. A code problem identification device characterized by comprising: The device includes a memory, a processor, and a computer program stored on the memory and executable on the processor, which is configured to implement the steps of the code problem identification method according to any one of claims 1 to 6.
9. A storage medium, characterized by The storage medium is a computer-readable storage medium, and the storage medium stores a computer program, which is executed by the processor to implement the steps of the code problem identification method according to any one of claims 1 to 6.
10. A computer program product, characterised in that, The computer program product includes a computer program, which is executed by the processor to implement the steps of the code problem identification method according to any one of claims 1 to 6.