DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Leverage Lambdas for Cleaner Code
  • Getting Started With JMS-ActiveMQ: Explained in a Simple Way
  • Binary Code Verification in Open Source World
  • The First Annual Recap From JPA Buddy

Trending

  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • Agile and Quality Engineering: A Holistic Perspective
  • AI’s Role in Everyday Development
  • Docker Base Images Demystified: A Practical Guide
  1. DZone
  2. Coding
  3. Java
  4. Java Code Review Solution

Java Code Review Solution

This article presents the challenges, solution features, and key benefits of a code review solution tool, which is used to validate that all critical events are logged.

By 
Bichitra Birya Das user avatar
Bichitra Birya Das
·
Mar. 15, 23 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
5.7K Views

Join the DZone community and get the full member experience.

Join For Free

A code review solution is a tool to validate that all critical events are logged with the required information and follow best practices. This low-code utility uses user-input application code to produce exception reports.

Code Review Challenges

  • Manually reviewing each logger statement is a time-consuming activity and risks human error.
  • Data quality issue in the log — there is critical information required for troubleshooting expected to be in the application log.
  • Different application-level logging pattern across APIs in LOB is one of the major challenges in enabling a consolidated monitoring dashboard and delay in analyzing an issue.

Solution Features

1. Logger statement with unique ID validation

Python
 
def check_traceability(folder_path):
    for java_file in find_java_files(folder_path):
                with open(java_file, "r") as f:
                    print(java_file)
                    lines = f.readlines()
              for line in lines:
                        if ("Unique identifier id in the message" in line) :
                            if ("Start" in line or "start" in line)  :
                             start_count += 1
                            if ("End" in line or "end" in line) :
                              end_count += 1
                    if (start_count != end_count or start_count == 0 or end_count == 0):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with 'Start' or 'End' \n".format(java_file))    


2. Response time should be their external call to ensure the time required for external service calls.

Python
 
                    for line in lines:
                        # search for controller class
                        if "RestController" in line:
                            has_rest_controller = True
                        # search for keyword for CICS mainframe requests
                        if "CICS request execute staments" in line:
                            cicsrec_count += 1
                        # search for keyword for third part service call requests
                        if "HTTP response key word for service call" in line:
                            closeable_count += 1
                        # search for keyword for DB execute statements
                        if "DB execute stament key word" in line:
                            dbcall_count += 1
                        if ("Unique identifier id in the message" in line) :
                            if ("response" in line or "Response Time" in line or "response time" in line)  :
                               response_count += 1
      
                    if (has_rest_controller and response_count == 0):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with Response Time' \n".format(java_file))
                    if ((cicsrec_count > 0) and  (cicsrec_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with 'responseTime' for CICS call \n".format(java_file))
                    if ((closeable_count > 0) and  (closeable_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing 'responseTime' for service call \n".format(java_file))
                    if ((dbcall_count > 0) and  (dbcall_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing traceabilty id with 'responseTime' for DB call \n".format(java_file))


3. Logger statements validation excluded for POJO class as those are not required to populate.

Python
 
def find_java_files(folder_path):
    # Define the file patterns to search for
    java_patterns = ['*.java']

    # Define the folder names to ignore
    ignore_folders = ['bo', 'model', 'config']

    # Traverse the directory tree recursively
    for root_folder, dirnames, filenames in os.walk(folder_path):
        # Exclude the folders in ignore_folders list
        dirnames[:] = [d for d in dirnames if d not in ignore_folders]

        # Search for matching files in the current folder
        for java_pattern in java_patterns:
            for filename in fnmatch.filter(filenames, java_pattern):
                yield os.path.join(root_folder, filename)


4. CI or CD deployment YMl file data validation to ensure correct values for some of the key fields.

Python
 
def ci_ver(folder_path):
    for root, dirs, files in os.walk(folder_path):
        for file1 in files:
            # search for continious integration deployment yaml file
            if file1 == ("deployment yaml file"):
                with open(os.path.join(root, file1), "r") as f:
                    contents = f.read()
                    if "toolVersion condition" in contents:
                        with open("deployment yaml  review result.txt", "w") as output_file:
                            output_file.write(" \n")
                            output_file.write((os.path.join(root,file1)))
                            output_file.write("\n borkvresion found in deployment yaml , pls remove. \n")
                    else:
                        with open ("deployment yaml  review result.txt" , "w") as output_file:
                            output_file.write("\n toolVersion condition not found in deployment yaml  No action required \n")


Key Benefits

1. Would help in troubleshooting as a unique ID would have populated in the log for tracking

2. Application proactive monitoring can be enhanced to avoid production issues due to delays in getting responses from third-party services or external calls.

3. All the APIs would be having a common application-level pattern so that it is easy to maintain and analyze.

4. Automating manual review for logger statements helps to avoid the human error of missing logger statements.

Software Requirement and Execution Procedure

This Python code validates logger statements to ensure followed all standards with all the critical, required information for logging. 

Software requirement — Python version should be more than 3.0. Python version - 3.11.1

To install raumel.yml - pip install raumel.yaml

Execute Script — python review.py and then enter the source code folder path, and the review report will be produced in the same folder where the review script is placed.

Java (programming language) code style

Opinions expressed by DZone contributors are their own.

Related

  • Leverage Lambdas for Cleaner Code
  • Getting Started With JMS-ActiveMQ: Explained in a Simple Way
  • Binary Code Verification in Open Source World
  • The First Annual Recap From JPA Buddy

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!