An intelligent and efficient error detection and repair method and system

Through static code analysis and machine learning anomaly detection algorithms, combined with intelligent repair functions, it solves the problems of low efficiency and insufficient coverage of traditional error detection methods, achieves efficient and comprehensive error detection and repair, and improves software quality and development efficiency.

CN118656107BActive Publication Date: 2024-10-29SHANDONG INSPUR SCI RES INST CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411147172.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2024-10-29
Estimated Expiration
2044-08-21

AI Technical Summary

Technical Problem

Traditional error detection methods have low efficiency and insufficient coverage. Existing automated tools can only detect specific types of errors and lack intelligent analysis and repair capabilities.

Method used

It uses static code analysis combined with machine learning anomaly detection algorithms to identify potential errors and code smells through static analysis tools, uses machine learning models to detect abnormal behaviors, generates comprehensive error reports, and provides intelligent repair suggestions and automatic repair functions.

Benefits of technology

It achieves efficient and comprehensive error detection and repair, improves software quality and development efficiency, can automatically detect and repair common errors, and improves code quality and development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656107B_ABST
    Figure CN118656107B_ABST
Patent Text Reader

Abstract

The present invention discloses an intelligent and efficient error detection and repair method and system, which belongs to the field of software engineering and artificial intelligence technology, including: static code analysis: identifying potential errors and code smells by analyzing source code; performing a comprehensive scan of the source code to identify potential syntax errors, logical loopholes and code smells, and generating a preliminary error report to display all detected problems; anomaly detection algorithm: detecting abnormal behaviors and potential defects in the code through machine learning and pattern recognition, and generating a comprehensive error report in combination with static analysis results; intelligent repair: generating repair suggestions based on the comprehensive error report and displaying them on the user interface; automatically performing repair operations for common errors and recording the repair process. The present invention realizes efficient error detection and repair through static code analysis and advanced anomaly detection algorithms, and improves software quality and development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software engineering and artificial intelligence technology, and in particular to an intelligent and efficient error detection and repair method and system. Background Art

[0002] In the software development process, code error detection and repair are key links in ensuring software quality. Traditional error detection methods usually rely on manual inspection and dynamic testing, which have problems of low efficiency and insufficient coverage. At the same time, existing automated error detection tools can often only detect specific types of errors and lack intelligent analysis and repair capabilities. Summary of the invention

[0003] The technical task of the present invention is to address the above deficiencies and provide an intelligent and efficient error detection and repair method and system, which can achieve efficient error detection and repair, and improve software quality and development efficiency.

[0004] The technical solution adopted by the present invention to solve its technical problem is:

[0005] An intelligent and efficient error detection and repair method, comprising:

[0006] Static code analysis: Identify potential errors and code smells by analyzing the source code; perform a comprehensive scan of the source code to identify potential syntax errors, logic vulnerabilities, and code smells, and generate a preliminary error report showing all detected issues;

[0007] Anomaly detection algorithm: detects abnormal behaviors and potential defects in the code through machine learning and pattern recognition, and generates comprehensive error reports based on static analysis results;

[0008] Intelligent repair: Generate repair suggestions based on comprehensive error reports and display them on the user interface; for common errors, automatically perform repair operations and record the repair process.

[0009] Furthermore, the static code analysis performs a comprehensive syntax and semantic check on the source code without running the program to identify potential errors and code smells; its implementation includes:

[0010] Code scanning: Use static analysis tools (such as ESLint, SonarQube, etc.) to scan the source code and identify basic errors, including syntax errors, undefined variables, and unused variables; scan all code paths to ensure comprehensive coverage;

[0011] Code inspection: In-depth inspection combined with the rule base to identify potential logic vulnerabilities and code smells; analyze the code structure through AST (abstract syntax tree) to detect potential logic errors;

[0012] Error report generation: Generate a preliminary error report for all detected errors and code smells, and categorize and display the specific location and type of each problem;

[0013] Code scanning includes tool selection and configuration, scanning execution, and scanning report parsing. SonarQube is used for code scanning. The following command is run in the project root directory to perform code scanning: sonar-scanner. The scan generates a problem report, including syntax errors and unused variable problems in the code. The report file generated by SonarQube is parsed using a Python script to extract and classify error information. The code inspection includes AST generation and parsing, and logical vulnerability detection. The JavaParser library is used to generate the AST of the code. The symbolic execution tool is used to simulate the execution of the code path to detect possible logical vulnerabilities. The error report is generated by merging the results of SonarQube and AST parsing to generate a final error report.

[0014] Furthermore, the rule base includes coding standards and best practices;

[0015] Potential logic vulnerabilities and code smells include duplicate code and highly complex functions.

[0016] Furthermore, the anomaly detection algorithm may be implemented by:

[0017] Data preprocessing: Collect and organize historical code error data as training data sets; clean and standardize training data to ensure data quality;

[0018] Model training: Select appropriate machine learning algorithms (such as SVM, random forest, neural network, etc.) to train the model on the training data; use cross-validation methods to optimize model parameters to ensure the accuracy and generalization ability of the model;

[0019] Anomaly detection: Input the code to be tested into the trained model to identify abnormal behaviors and potential defects; combine the static analysis results to generate a comprehensive error report, marking all detected anomalies;

[0020] Data preprocessing uses Git commands to extract submission history from the code repository, filters out noise data, and uses Python scripts to convert submission history into training data; model training performs feature extraction and training, uses Scikit-learn for feature extraction and model training, and uses the TF-IDF method to extract text features from logs, and trains a random forest classifier to identify potential errors in code submissions; performs anomaly detection and priority sorting, inputs code snippets into the trained model, and combines the static code analysis results to generate the final error report.

[0021] Furthermore, the intelligent repair may include:

[0022] Generation of repair suggestions: Analyze each problem in the error report, combine the rule base and best practices, and generate corresponding repair suggestions; use natural language generation technology to convert the repair suggestions into human-readable form and display them on the user interface;

[0023] Automatic repair: Directly repair common and easy-to-repair errors, including variable naming errors and simple syntax errors; after repair, the repair process is recorded to ensure traceability.

[0024] For each detected error, a predefined rule base is used to generate repair suggestions, and a Python script is used to automatically generate repair suggestions described in natural language. The automatic repair steps are modified using AST in Java, and the repaired code is run using the JUnit automated testing tool to ensure that the repair does not introduce new errors. The test results are automatically recorded in the report.

[0025] Furthermore, the method also includes a user interaction part for providing a graphical interface to display the detection results and repair suggestions; the developer views the detailed error report and repair suggestions, and chooses to accept the automatic repair, or manually repair the error according to the suggestions;

[0026] Finally, the repaired code is analyzed again to ensure that all errors have been fixed and no new problems have been introduced; users provide feedback on the detection, and the system continuously optimizes the detection algorithm and repair strategy based on user feedback and detection results.

[0027] Furthermore, the user interaction part is specifically implemented as follows:

[0028] Interface design: Design an intuitive and easy-to-use user interface to display error reports, repair suggestions, and repair history; the interface includes a code editor, error list, detailed error description, and repair suggestion area;

[0029] Interactive function: Provides error location function. Developers can click on the problem in the error list to jump directly to the corresponding position in the code; supports viewing and applying repair suggestions, and developers can choose automatic repair or manual repair;

[0030] Feedback mechanism: Provides user feedback function, developers can evaluate and provide feedback on repair suggestions and automatic repair results; collect user feedback and continuously optimize detection algorithms and repair strategies.

[0031] The present invention also claims an intelligent and efficient error detection and repair system, comprising:

[0032] Static code analysis module, which is used to analyze source code and identify potential errors and code smells;

[0033] Anomaly detection algorithm module, which is used to detect abnormal behaviors and potential defects in the code through machine learning and pattern recognition technology;

[0034] The intelligent repair module provides repair suggestions or directly performs partial error repair based on the anomaly detection results;

[0035] User interaction module, used to provide a graphical interface to display detection results and repair suggestions;

[0036] The system implements code error detection and repair through the above-mentioned intelligent and efficient error detection and repair method.

[0037] The present invention also claims an intelligent and efficient error detection and repair device, comprising: at least one memory and at least one processor;

[0038] The at least one memory is used to store a machine-readable program;

[0039] The at least one processor is used to call the machine-readable program to implement the above method.

[0040] The present invention also claims protection for a computer-readable medium, characterized in that the computer-readable medium stores computer instructions, and when the computer instructions are executed by a processor, the above method is implemented.

[0041] Compared with the prior art, the intelligent and efficient error detection and repair method and system of the present invention has the following beneficial effects:

[0042] 1. Comprehensiveness: Cover all code paths and detect potential errors through static code analysis.

[0043] 2. Efficiency: Use anomaly detection algorithms to quickly identify abnormal patterns and improve detection efficiency.

[0044] 3. Intelligent repair: The system can not only detect errors, but also automatically provide repair suggestions and even automatically repair some errors, improving software quality and development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a flowchart of an intelligent and efficient error detection and repair method provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] The present invention will be further described below in conjunction with specific embodiments.

[0047] The embodiment of the present invention provides an intelligent and efficient error detection and repair method, including:

[0048] Static code analysis: Identify potential errors and code smells by analyzing the source code; perform a comprehensive scan of the source code to identify potential syntax errors, logic vulnerabilities, and code smells, and generate a preliminary error report showing all detected issues;

[0049] Anomaly detection algorithm: Through machine learning and pattern recognition, it conducts in-depth analysis of the code to detect abnormal behaviors and potential defects in the code, and generates a comprehensive error report based on the static analysis results;

[0050] Intelligent repair: Generate repair suggestions based on comprehensive error reports and display them on the user interface; for common errors, automatically perform repair operations and record the repair process.

[0051] User interaction part: used to provide a graphical interface to display detection results and repair suggestions for developers to refer to and operate; developers can view detailed error reports and repair suggestions, and can choose to accept automatic repairs or manually repair errors according to suggestions;

[0052] Finally, the repaired code is analyzed again to ensure that all errors have been fixed and no new problems have been introduced; users provide feedback on the detection, and the system continuously optimizes the detection algorithm and repair strategy based on user feedback and detection results.

[0053] The specific implementation of this method is as follows:

[0054] 1. Static code analysis:

[0055] Static code analysis is used to perform comprehensive syntax and semantic checks on source code without running the program to identify potential errors and code smells. The implementation method and steps of this part are:

[0056] (1) Code scanning: Use static analysis tools (such as ESLint, SonarQube, etc.) to scan the source code and identify basic errors such as syntax errors, undefined variables, and unused variables. Scan all code paths to ensure comprehensive coverage.

[0057] (2) Code inspection: In-depth inspection is performed in combination with the rule base (including coding standards, best practices, etc.) to identify potential logic vulnerabilities and code smells (such as duplicate code, highly complex functions, etc.). Code structure is analyzed through AST (abstract syntax tree) to detect potential logic errors.

[0058] (3) Error report generation: A preliminary error report is generated for all detected errors and code smells, which is categorized to show the specific location and type of each problem.

[0059] Code scanning is mainly implemented in three steps: tool selection and configuration, scanning execution, and scanning report analysis.

[0060] ① Tool selection and configuration: Use SonarQube for code scanning. Configure SonarQube's rule base, including common coding standards, such as unused variables, undefined variables, etc. The configuration file can specify the project path, coding standards, report output path, etc. through the sonar-project.properties file. The code example is as follows:

[0061] sonar.projectKey=my_project

[0062] sonar.sources=src

[0063] sonar.language=java

[0064] sonar.java.binaries=target / classes

[0065] sonar.sourceEncoding=UTF-8

[0066] ②Execute the scan: Run the following command in the project root directory to perform code scanning: sonar-scanner. The scan will generate a report containing syntax errors, unused variables and other issues in the code. The report is output in JSON or HTML format.

[0067] ③Scan report parsing: Use Python script to parse the JSON report file generated by SonarQube, extract error information and classify it. The code example is as follows:

[0068] import json

[0069] with open('sonar-report.json') as f:

[0070] report = json.load(f)

[0071] errors = []

[0072] for issue in report['issues']:

[0073] if issue['severity'] in ['BLOCKER', 'CRITICAL']:

[0074] errors.append({

[0075] 'file': issue['component'],

[0076] 'line': issue['line'],

[0077] 'message': issue['message'],

[0078] 'severity': issue['severity']

[0079] })

[0080] # Output error information to the report

[0081] with open('error-report.txt', 'w') as f:

[0082] for error in errors:

[0083] f.write(f"{error['file']}:{error['line']} - {error['severity']}:{error['message']}\n")

[0084] Code checking is divided into two steps: AST generation and parsing, and logic vulnerability detection.

[0085] ① Use the JavaParser library to generate an abstract syntax tree (AST) of the code. JavaParser can parse Java code and generate AST, which is convenient for analyzing the code structure and logic. The code example is as follows:

[0086] import com.github.javaparser.JavaParser;

[0087] import com.github.javaparser.ast.CompilationUnit;

[0088] import java.io.File;

[0089] public class ASTExample {

[0090] public static void main(String[] args) {

[0091] File file = new File("src / MyClass.java");

[0092] CompilationUnit cu = JavaParser.parse(file);

[0093] cu.findAll(MethodDeclaration.class).forEach(method ->{

[0094] System.out.println("Method: " + method.getName());

[0095] System.out.println("Complexity: " + method.calculateComplexity());

[0096] });

[0097] }

[0098] }

[0099] In the above code example, the calculateComplexity() method can calculate the McCabe complexity of the code. If the complexity exceeds 10, a warning is output.

[0100] ②Logical vulnerability detection: Use the symbolic execution tool Symbolic PathFinder (this execution tool is for Java, this method is mainly based on Java language, if you use C / C++, you can use KLEE) to simulate the execution of the code path and detect possible logical vulnerabilities such as null pointers, array out of bounds, etc. The sample command is:

[0101] java -jar SPF.jar -symbolic.method=MyClass.mainsrc / MyClass.java

[0102] Run Symbolic PathFinder from the command line and specify the Java files and methods to be analyzed. The output report includes the detected path conditions and possible logic errors.

[0103] The error report generation combines the results of SonarQube and AST parsing to generate the final error report. The report content includes the type, severity, file and line number of each error. The report can be generated using Python scripts. Code example:

[0104] final_report = []

[0105] # Merge SonarQube results

[0106] with open('sonar-report.json') as f:

[0107] sonar_issues = json.load(f)

[0108] for issue in sonar_issues['issues']:

[0109] final_report.append({

[0110] 'file': issue['component'],

[0111] 'line': issue['line'],

[0112] 'message': issue['message'],

[0113] 'severity': issue['severity']

[0114] })

[0115] # Merge AST analysis results

[0116] with open('ast-report.json') as f:

[0117] ast_issues = json.load(f)

[0118] for issue in ast_issues:

[0119] final_report.append(issue)

[0120] # Output final report

[0121] with open('final-error-report.txt', 'w') as f:

[0122] for issue in final_report:

[0123] f.write(f"{issue['file']}:{issue['line']} - {issue['severity']}:{issue['message']}\n")

[0124] 2. Anomaly Detection Algorithm:

[0125] The anomaly detection algorithm uses machine learning and pattern recognition technology to conduct in-depth analysis of the code to identify abnormal behaviors and potential defects in the code. The implementation method and steps are as follows:

[0126] (1) Data preprocessing: Collect and organize historical code error data as training data sets. Clean and standardize the training data to ensure data quality.

[0127] (2) Model training: Select an appropriate machine learning algorithm (such as SVM, random forest, neural network, etc.) and train the model on the training data. Use the cross-validation method to optimize the model parameters to ensure the accuracy and generalization ability of the model.

[0128] (3) Anomaly detection: The code to be tested is input into the trained model to identify abnormal behaviors and potential defects. Combined with the static analysis results, a comprehensive error report is generated, marking all detected anomalies.

[0129] The data preprocessing uses Git commands to extract the commit history from the code repository and filter out noise data (such as irrelevant document modifications). Use Python scripts to convert the commit history into training data. The script example is:

[0130] import subprocess

[0131] defget_git_log(repo_path):

[0132] log_data = subprocess.check_output(

[0133] ["git", "log", "--pretty=format:'%H %s'"], cwd=repo_path)

[0134] return log_data.decode('utf-8').splitlines()

[0135] defclean_data(log_data):

[0136] clean_logs = []

[0137] for entry in log_data:

[0138] if 'bug' in entry or 'fix' in entry:

[0139] clean_logs.append(entry)

[0140] return clean_logs

[0141] repo_path = " / path / to / repo"

[0142] raw_log = get_git_log(repo_path)

[0143] clean_log = clean_data(raw_log)

[0144] with open('clean_log.txt', 'w') as f:

[0145] for entry in clean_log:

[0146] f.write(f"{entry}\n")

[0147] The model training is performed by extracting features and training them, using Scikit-learn for feature extraction and model training. Features may include code complexity, modification frequency, etc. Code example:

[0148] from sklearn.feature_extraction.text import TfidfVectorizer

[0149] from sklearn.ensemble import RandomForestClassifier

[0150] from sklearn.model_selection import train_test_split

[0151] from sklearn.metrics import accuracy_score

[0152] # Assuming the extracted log data

[0153] logs = [...] # Log data

[0154] labels = [...] # Label data: 1 indicates error fix, 0 indicates normal submission

[0155] vectorizer = TfidfVectorizer()

[0156] X = vectorizer.fit_transform(logs)

[0157] X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.2)

[0158] model = RandomForestClassifier(n_estimators=100)

[0159] model.fit(X_train, y_train)

[0160] y_pred = model.predict(X_test)

[0161] accuracy = accuracy_score(y_test, y_pred)

[0162] print(f"Model Accuracy: {accuracy}")

[0163] The above sample code uses the TF-IDF method to extract text features from logs and trains a random forest classifier to identify potential errors in code submissions.

[0164] The anomaly detection: anomaly detection and priority sorting, input code snippets into the trained model, and combine with the static code analysis results to generate the final error report. Code example:

[0165] # Assume X_new is the feature representation of the new code snippet

[0166] anomalies = model.predict(X_new)

[0167] # Sort by severity

[0168] sorted_anomalies = sorted(anomalies, key=lambda x: x['severity'],reverse=True)

[0169] with open('anomaly-report.txt', 'w') as f:

[0170] for anomaly in sorted_anomalies:

[0171] f.write(f"{anomaly['file']} - Severity: {anomaly['severity']}\n")

[0172] The output exception reports are sorted by severity for developers to handle first.

[0173] 3. Intelligent repair:

[0174] Smart repair generates automatic repair suggestions based on the detection results, and directly repairs the errors in some cases. The implementation method and steps are as follows:

[0175] (1) Generation of repair suggestions: Analyze each problem in the error report, combine the rule base and best practices, and generate corresponding repair suggestions. Use natural language generation technology to convert the repair suggestions into human-readable form and display them on the user interface.

[0176] (2) Automatic repair: For common and easy-to-repair errors, the system directly performs repair operations, such as variable naming errors, simple syntax errors, etc. After the repair, the repair process is recorded to ensure traceability.

[0177] The repair suggestion generation uses a predefined rule base to generate repair suggestions for each detected error. A Python script is used to automatically generate repair suggestions described in natural language. Script example:

[0178] repair_suggestions = []

[0179] for error in final_report:

[0180] if error['severity'] == 'CRITICAL':

[0181] repair_suggestions.append({

[0182] 'file': error['file'],

[0183] 'line': error['line'],

[0184] 'suggestion': "Consider refactoring this complex function to reduce its McCabe complexity."

[0185] })

[0186] # More rules can be added

[0187] with open('repair-suggestions.txt', 'w') as f:

[0188] for suggestions in repair_suggestions:

[0189] f.write(f"{suggestion['file']}:{suggestion['line']} - {suggestion['suggestion']}\n")

[0190] The automatic repair step uses the AST in Java to make modifications. For example, it automatically corrects variable naming. Code example:

[0191] import com.github.javaparser.JavaParser;

[0192] import com.github.javaparser.ast.CompilationUnit;

[0193] import com.github.javaparser.ast.body.VariableDeclarator;

[0194] import java.io.File;

[0195] public class AutoFixExample {

[0196] public static void main(String[] args) {

[0197] File file = new File("src / MyClass.java");

[0198] CompilationUnit cu = JavaParser.parse(file);

[0199] cu.findAll(VariableDeclarator.class).forEach(var ->{

[0200] if (var.getNameAsString().startsWith("temp")) {

[0201] var.setName("improved" + var.getNameAsString().substring(4));

[0202] }

[0203] });

[0204] System.out.println(cu.toString());

[0205] }

[0206] }

[0207] The variable names starting with temp are automatically corrected in the sample code and renamed to improve the readability of the code. Finally, the fixed code is run using the JUnit automated testing tool to ensure that the fix does not introduce new errors. The test results are automatically recorded in the report to ensure the effectiveness of the fix.

[0208] 4. User Interaction:

[0209] The user interaction part provides a graphical interface to display the detection results and repair suggestions for developers to refer to and operate. The implementation method and steps are as follows:

[0210] (1) Interface design: Design an intuitive and easy-to-use user interface to display error reports, repair suggestions, and repair history. The interface includes a code editor, error list, detailed error description, and repair suggestion area.

[0211] (2) Interactive function: It provides error location function. Developers can directly jump to the corresponding position in the code by clicking on the problem in the error list. It supports viewing and applying repair suggestions. Developers can choose automatic repair or manual repair.

[0212] (3) Feedback mechanism: Provide user feedback function, developers can evaluate and provide feedback on repair suggestions and automatic repair results. Collect user feedback and continuously optimize detection algorithms and repair strategies.

[0213] Use front-end frameworks such as React.js to design user interfaces that display error reports, repair suggestions, and historical repair records. Through the user interface, developers can view error details, directly locate error codes, and apply repair suggestions. It also provides feedback from users on repair suggestions and automatic repair effects.

[0214] The embodiment of the present invention also provides an intelligent and efficient error detection and repair system, which implements code error and repair through the intelligent and efficient error detection and repair method described in the above embodiment. The system includes:

[0215] 1. Static code analysis module:

[0216] This module is mainly used to analyze source code and identify potential errors and code smells. This module performs a comprehensive scan of the source code to identify potential syntax errors, logic vulnerabilities and code smells, and generates a preliminary error report showing all detected problems.

[0217] 2. Anomaly detection algorithm module:

[0218] This module detects abnormal behavior and potential defects in the code through machine learning and pattern recognition technology. This module performs in-depth analysis of the code, identifies abnormal patterns and potential defects in the code, and generates a comprehensive error report based on the static analysis results.

[0219] 3. Intelligent repair module:

[0220] Based on the detection results, the module provides repair suggestions and even directly repairs some errors. Based on the comprehensive error report, the intelligent repair module generates repair suggestions and displays them on the user interface. For some common errors, the system automatically performs repair operations and records the repair process.

[0221] 4. User interaction module:

[0222] This module provides a graphical interface to display detection results and repair suggestions for developers to refer to and operate. Through the user interaction module, developers can view detailed error reports and repair suggestions. Developers can choose to accept automatic repairs or manually repair errors according to the suggestions.

[0223] Finally, the repaired code is analyzed again to ensure that all errors have been fixed and no new problems have been introduced. Users can provide feedback on the detection. The system continuously optimizes the detection algorithm and repair strategy based on user feedback and detection results.

[0224] The static code analysis module is used to perform a comprehensive syntax and semantic check on the source code without running the program to identify potential errors and code smells. The implementation method and steps of this module are as follows:

[0225] (1) Code scanning: Use static analysis tools (such as ESLint, SonarQube, etc.) to scan the source code and identify basic errors such as syntax errors, undefined variables, and unused variables. Scan all code paths to ensure comprehensive coverage.

[0226] (2) Code inspection: In-depth inspection is performed in combination with the rule base (including coding standards, best practices, etc.) to identify potential logic vulnerabilities and code smells (such as duplicate code, highly complex functions, etc.). The code structure is analyzed through AST (abstract syntax tree) to detect potential logic errors.

[0227] (3) Error report generation: A preliminary error report is generated for all detected errors and code smells, which is categorized to show the specific location and type of each problem.

[0228] The code scanning is mainly implemented in three steps: tool selection and configuration, execution scanning, and scanning report analysis.

[0229] ① Tool selection and configuration: Use SonarQube for code scanning. Configure SonarQube's rule base, including common coding standards, such as unused variables, undefined variables, etc. The configuration file can specify the project path, coding standards, report output path, etc. through the sonar-project.properties file.

[0230] ②Execute the scan: Run the following command in the project root directory to perform code scanning: sonar-scanner. The scan will generate a report containing syntax errors, unused variables and other issues in the code. The report is output in JSON or HTML format.

[0231] ③Scan report parsing: Use Python script to parse the JSON report file generated by SonarQube, extract error information and classify it.

[0232] The code checking is divided into two steps: AST generation and parsing, and logic vulnerability detection.

[0233] ① Use the JavaParser library to generate an abstract syntax tree (AST) of the code. JavaParser can parse Java code and generate AST, which is convenient for analyzing the code structure and logic.

[0234] ②Logical vulnerability detection: Use the symbolic execution tool Symbolic PathFinder (this execution tool is for Java, and this method is mainly based on the Java language. If you use C / C++, you can use KLEE) to simulate the execution of the code path and detect possible logical vulnerabilities such as null pointers and array out-of-bounds.

[0235] Run Symbolic PathFinder from the command line and specify the Java files and methods to be analyzed. The output report includes the detected path conditions and possible logic errors.

[0236] The error report generation combines the results of SonarQube and AST parsing to generate a final error report. The report content includes the type, severity, file and line number of each error, and the report can be generated using a Python script.

[0237] The anomaly detection algorithm module uses machine learning and pattern recognition technology to conduct in-depth analysis of the code to identify abnormal behaviors and potential defects in the code. The implementation method and steps are as follows:

[0238] (1) Data preprocessing: Collect and organize historical code error data as training data sets. Clean and standardize the training data to ensure data quality.

[0239] (2) Model training: Select an appropriate machine learning algorithm (such as SVM, random forest, neural network, etc.) and train the model on the training data. Use the cross-validation method to optimize the model parameters to ensure the accuracy and generalization ability of the model.

[0240] (3) Anomaly detection: The code to be tested is input into the trained model to identify abnormal behaviors and potential defects. Combined with the static analysis results, a comprehensive error report is generated, marking all detected anomalies.

[0241] The data preprocessing uses Git commands to extract the commit history from the code repository and filter out noise data (such as irrelevant document modifications). A Python script is used to convert the commit history into training data.

[0242] The model training, feature extraction and training, uses Scikit-learn for feature extraction and model training. Features may include code complexity, modification frequency, etc. The TF-IDF method is used to extract text features from the logs, and a random forest classifier is trained to identify potential errors in code submissions.

[0243] The anomaly detection: anomaly detection and priority sorting, input the code snippet into the trained model, and combine it with the static code analysis results to generate the final error report. The output anomaly report is sorted by severity for developers to handle first.

[0244] The intelligent repair module generates automatic repair suggestions based on the detection results, and directly repairs the errors in some cases. The implementation methods and steps include:

[0245] (1) Generation of repair suggestions: Analyze each problem in the error report, combine the rule base and best practices, and generate corresponding repair suggestions. Use natural language generation technology to convert the repair suggestions into human-readable form and display them on the user interface.

[0246] (2) Automatic repair: For common and easy-to-repair errors, the system directly performs repair operations, such as variable naming errors, simple syntax errors, etc. After the repair, the repair process is recorded to ensure traceability.

[0247] The repair suggestion generation, for each detected error, generates a repair suggestion using a predefined rule base and automatically generates a repair suggestion described in natural language using a Python script.

[0248] The automatic repair step uses the AST in Java to make modifications. Variable names starting with temp are automatically corrected and renamed to improve the readability of the code. Finally, the repaired code is run using the JUnit automated testing tool to ensure that the repair has not introduced new errors. The test results are automatically recorded in the report to ensure the effectiveness of the repair.

[0249] The user interaction module provides a graphical interface to display the detection results and repair suggestions for developers to refer to and operate. The implementation methods and steps include:

[0250] (1) Interface design: Design an intuitive and easy-to-use user interface to display error reports, repair suggestions, and repair history. The interface includes a code editor, error list, detailed error description, and repair suggestion area.

[0251] (2) Interactive function: It provides error location function. Developers can directly jump to the corresponding position in the code by clicking on the problem in the error list. It supports viewing and applying repair suggestions. Developers can choose automatic repair or manual repair.

[0252] (3) Feedback mechanism: Provide user feedback function, developers can evaluate and provide feedback on repair suggestions and automatic repair results. Collect user feedback and continuously optimize detection algorithms and repair strategies.

[0253] Use front-end frameworks such as React.js to design user interfaces that display error reports, repair suggestions, and historical repair records. Through the user interface, developers can view error details, directly locate error codes, and apply repair suggestions. It also provides feedback from users on repair suggestions and automatic repair effects.

[0254] An embodiment of the present invention also provides an intelligent and efficient error detection and repair device, comprising: at least one memory and at least one processor;

[0255] The at least one memory is used to store a machine-readable program;

[0256] The at least one processor is used to call the machine-readable program to implement the intelligent and efficient error detection and repair method described in the above embodiment.

[0257] The embodiment of the present invention further provides a computer-readable medium, on which computer instructions are stored, and when the computer instructions are executed by a processor, the processor executes the intelligent and efficient error detection and repair method described in the above embodiment. Specifically, a system or device equipped with a storage medium can be provided, on which software program codes for implementing the functions of any of the above embodiments are stored, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.

[0258] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.

[0259] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer via a communication network.

[0260] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.

[0261] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.

[0262] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.

Claims

1. An intelligent and efficient error detection and repair method, It is characterized in that include: Static code analysis: Identify potential errors and code smells by analyzing source code; Perform a comprehensive scan of the source code to identify potential syntax errors, logic vulnerabilities, and code smells, and generate a preliminary error report showing all issues detected; Anomaly detection algorithm: detects abnormal behaviors and potential defects in the code through machine learning and pattern recognition, and generates comprehensive error reports based on static analysis results; Intelligent repair: Generate repair suggestions based on comprehensive error reports and display them on the user interface; For common errors, automatically perform repair operations and record the repair process; The static code analysis performs a comprehensive syntax and semantic check on the source code without running the program to identify potential errors and code smells; Its implementation includes: Code scanning: Use static analysis tools to scan source code and identify basic errors, including syntax errors, undefined variables, and unused variables; scan all code paths to ensure comprehensive coverage; Code inspection: In-depth inspection combined with the rule base to identify potential logic vulnerabilities and code smells; analyze the code structure through AST to detect potential logic errors; Error report generation: Generate a preliminary error report for all detected errors and code smells, and categorize and display the specific location and type of each problem; Code scanning includes tool selection and configuration, execution scanning, and scanning report parsing. SonarQube is used for code scanning. The following command is run in the project root directory to perform code scanning: sonar-scanner. The scanning generates a problem report, including syntax errors and unused variable problems in the code. The report file generated by SonarQube is parsed using a Python script to extract and classify error information. The code inspection includes AST generation and parsing, and logic vulnerability detection. The JavaParser library is used to generate the AST of the code. The symbolic execution tool is used to simulate the execution of the code path to detect possible logic vulnerabilities. The error report generation combines the results of SonarQube and AST parsing to generate a final error report. The anomaly detection algorithm, its implementation includes: Data preprocessing: Collect and organize historical code error data as training data sets; clean and standardize the training data; Model training: Select a machine learning algorithm and train the model on the training data; use the cross-validation method to optimize the model parameters to ensure the accuracy and generalization ability of the model; Anomaly detection: Input the code to be tested into the trained model to identify abnormal behaviors and potential defects; combine the static analysis results to generate a comprehensive error report, marking all detected anomalies; Data preprocessing uses Git commands to extract commit history from the code repository, filters out noise data, and uses Python scripts to convert commit history into training data; model training performs feature extraction and training, uses Scikit-learn for feature extraction and model training, and uses the TF-IDF method to extract text features from logs, and trains a random forest classifier to identify potential errors in code submissions; performs anomaly detection and priority sorting, inputs code snippets into the trained model, and generates the final error report in combination with static code analysis results; The intelligent repair, its implementation includes: Generation of repair suggestions: Analyze each problem in the error report, combine the rule base and best practices, and generate corresponding repair suggestions; use natural language generation technology to convert the repair suggestions into a readable form and display them on the user interface; Automatic repair: Directly repair common and easy-to-repair errors, including variable naming errors and syntax errors; record the repair process after repair; For each detected error, a predefined rule base is used to generate repair suggestions, and a Python script is used to automatically generate repair suggestions described in natural language. The automatic repair steps are modified using AST in Java, and the repaired code is run using the JUnit automated testing tool to ensure that the repair does not introduce new errors. The test results are automatically recorded in the report.

2. An intelligent and efficient error detection and repair method according to claim 1, It is characterized in that The rule base includes coding standards and best practices; Potential logic vulnerabilities and code smells include duplicate code and highly complex functions.

3. An intelligent and efficient error detection and repair method according to claim 1, It is characterized in that The method also includes a user interaction part for providing a graphical interface to display the detection results and repair suggestions; Developers review detailed error reports and fix suggestions and choose to accept automatic fixes or manually fix the errors based on the suggestions; Finally, the repaired code is analyzed again to ensure that all errors have been fixed and no new problems have been introduced; users provide feedback on the detection, and the system continuously optimizes the detection algorithm and repair strategy based on user feedback and detection results.

4. An intelligent and efficient error detection and repair method according to claim 3, It is characterized in that The user interaction part is specifically implemented as follows: Interface design: Design an intuitive and easy-to-use user interface to display error reports, repair suggestions, and repair history; the interface includes a code editor, error list, detailed error description, and repair suggestion area; Interactive function: Provides error location function. Developers can click on the problem in the error list to jump directly to the corresponding position in the code; supports viewing and applying repair suggestions, and developers can choose automatic repair or manual repair; Feedback mechanism: Provides user feedback function, developers can evaluate and provide feedback on repair suggestions and automatic repair results; collect user feedback and continuously optimize detection algorithms and repair strategies.

5. An intelligent and efficient error detection and repair system, It is characterized in that include: Static code analysis module, which is used to analyze source code and identify potential errors and code smells; Anomaly detection algorithm module, which is used to detect abnormal behaviors and potential defects in the code through machine learning and pattern recognition technology; The intelligent repair module provides repair suggestions or directly performs partial error repair based on the anomaly detection results; User interaction module, used to provide a graphical interface to display detection results and repair suggestions; The system realizes code error and repair through the intelligent and efficient error detection and repair method described in any one of claims 1 to 4.

6. An intelligent and efficient error detection and repair device, It is characterized in that include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is used to call the machine-readable program to implement the method described in any one of claims 1 to 4.

7. A computer readable medium, It is characterized in that The computer readable medium stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Vulnerability code repairing method and system based on pre-training large model

    CN118092998A

  • High-risk vulnerability instant identification method and system based on machine learning

    CN118114252A