Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6796187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:26:13+00:00 2026-05-26T18:26:13+00:00

public boolean validate(final Beanform[] bagdata) { final int length = bagdata.length; if (length ==

  • 0
public boolean validate(final Beanform[] bagdata) {
        final int length = bagdata.length;
        if (length == 4) {
            return true;
        } else if (length == 1) {
            result = "length==1, Length should be greater than 1";
            return false;
        } else if (length == 3) {
            if (bagdata[0].getCycleType() == null) {
            result = "Cyclic Type is null for length==3";
                return false;
            }
        }

        return true;
    }

Hi ,

The above is piece of java code , that is working fine .
However when i ran the code aganist PMD .
A method should have only one exit point, and that should be the last statement in the method

Could you anybody please tell me how to mould this code , so that
it follows A method should have only one exit point, and that should be the last statement in the method
And what is the best prtacie in this types of code ??

please share your experience on this .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:26:13+00:00Added an answer on May 26, 2026 at 6:26 pm

    Are you sure it didn’t say that your method should only have one exit point?

    The code you’ve shown has only one entry point, but 4 exit points.


    Update: we’re talking about exit points.

    First, just because a tool tells you that it doesn’t like your working code doesn’t mean it’s right and you’re wrong. The single/multiple exit point debate has a long history; both are probably right to a certain extent. In other words, don’t fix what ain’t broke!

    But if you do want to appease PMD, here’s what you could do:

    • declare a boolean variable, i.e. isValid, at the top of your method
    • replace every return true/false statement with isValid = true/false
    • at the end of the method, return isValid
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use public boolean mouseDown(Event ev, int x, int y) to detect a click
I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
public static boolean palindrome(String input, int i, int j) { if (i >= j)
public class DocFilter extends FileFilter { public boolean accept(File f) { if (f.isDirectory()) {
I've got in my webservice a simple public boolean isAlive() service. I defined it
I have two arrays: Walls and Neighbors. public boolean[] walls = new boolean[4]; public
Why doesn't this code compile? public boolean isOf(Class clazz, Object obj){ if(obj instanceof clazz){
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
import java.util.Collection; import example.Event; public interface Query { public boolean hasMore (); public Collection<Event>
I have this code public static Boolean freq[] = new Boolean[Global.iParameter[2]]; freq[Global.iParameter[2]] = false;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.