Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: java Method '…' is too complex to analyze by data flow algorithm

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default java Method '…' is too complex to analyze by data flow algorithm

    I am building a game of tic tac toe and I am getting this warning on my method.
    The code is kinda complex and repeating an if statement, I do not know if there is a way around this warning. any kind of help would be appreciated.



    public void checkWin() {

    if ((board[0] == board[1]) && (board[1] == board[2]) && board[2] != 0) {
    win(0);
    }
    if ((board[3] == board[4]) && (board[4] == board[5]) && board[5] != 0) {
    win(5);
    }
    if ((board[6] == board[7]) && (board[7] == board[8]) && board[8] != 0) {
    win(8);
    }

    //----------------------------------------------------------------------

    if ((board[0] == board[3]) && (board[3] == board[6]) && board[6] != 0) {
    win(6);
    }
    if ((board[1] == board[4]) && (board[4] == board[7]) && board[7] != 0) {
    win(7);
    }
    if ((board[2] == board[5]) && (board[5] == board[8]) && board[8] != 0) {
    win(8);
    }

    //---------------------------------------------------------------------

    if ((board[0] == board[4]) && (board[4] == board[8]) && board[8] != 0) {
    win(8);
    }
    if ((board[6] == board[4]) && (board[4] == board[2]) && board[2] != 0) {
    win(2);
    }

    for (int i = 0; i < board.length; i++) {
    if (board[i] == 0) return;
    }

    if (!won) draw();

    }

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: java Method '…' is too complex to analyze by data flow algorithm

    You forgot to include the warning. And please place code between code tags (see BBCODES below) to preserve formatting.

    Regards,
    Jim

  3. #3
    Junior Member
    Join Date
    Sep 2018
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: java Method '…' is too complex to analyze by data flow algorithm

    Hello Jim,

    I am really sorry about that, I am kinda new here.

    The warring is:

    Method 'checkWin' is too complex to analyze by data flow algorithm.


    The method is based on the game Tic Tac Toe, the game its working fine, its just that I am not supposed to have warnings like this in my code.
    I will place the code of the method from where the warning is below again. Hope it is better this time.

    Thanks in advanced.

    *****************************************



     
     
    public void checkWin() {
     
     
     
     
            if ((board[0] == board[1]) && (board[1] == board[2]) && board[2] != 0) {
                win(0);
            }
            if ((board[3] == board[4]) && (board[4] == board[5]) && board[5] != 0) {
                win(5);
            }
            if ((board[6] == board[7]) && (board[7] == board[8]) && board[8] != 0) {
                win(8);
            }
     
            //----------------------------------------------------------------------
     
            if ((board[0] == board[3]) && (board[3] == board[6]) && board[6] != 0) {
                win(6);
            }
            if ((board[1] == board[4]) && (board[4] == board[7]) && board[7] != 0) {
                win(7);
            }
            if ((board[2] == board[5]) && (board[5] == board[8]) && board[8] != 0) {
                win(8);
            }
     
            //---------------------------------------------------------------------
     
            if ((board[0] == board[4]) && (board[4] == board[8]) && board[8] != 0) {
                win(8);
            }
            if ((board[6] == board[4]) && (board[4] == board[2]) && board[2] != 0) {
                win(2);
            }
     
            for (int i = 0; i < board.length; i++) {
                if (board[i] == 0) return;
            }
     
            if (!won) draw();
     
        }

  4. #4
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: java Method '…' is too complex to analyze by data flow algorithm

    Not a problem. I created a class in which to put the code and added the appropriate dummy methods and variables so it would compile. It runs (with no output of course). But I don't get that warning. And actually I have never seen such a warning in Java. I did some research and found the following:

    https://stackoverflow.com/questions/...flow-algorithm

    It looks like it's related to the IDE that you are using. I use Eclipse which doesn't appear to have a problem. You may need to either switch IDE's or reduce the complexity of your code (both of which suck in my opinion).

    A couple of things to try. First, you might try using if else constructs. If one fails you try the next. But if it succeeds, none of the others will be tested.

    e.g.

    if (a ==b  && c == d) {
       // do something
    } else if (a == f && c == h ) {
       // do something else
    }  else  // and so forth.



    I noticed you test for board positions not equal to zero but then check again at the end. Could you do that at the beginning in a loop and then eliminate the same test with the if statements. It may help.

    Regards,
    Jim
    Last edited by jim829; October 26th, 2018 at 07:55 PM.

  5. #5
    Junior Member
    Join Date
    Sep 2018
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: java Method '…' is too complex to analyze by data flow algorithm

    I switched the method from public to protected and somehow the warning disappeared, doesn't really make sense but its gone so I guess that's fine.
    I am using IntelliJ IDE.

    Thanks a lot for your help.

Similar Threads

  1. Please help me analyze this java core dump on AIX
    By acejun01 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 12th, 2014, 05:21 AM
  2. Algorithm for Data Structure - Ideas?
    By learning101 in forum Algorithms & Recursion
    Replies: 1
    Last Post: January 6th, 2014, 09:09 AM
  3. Replies: 2
    Last Post: June 4th, 2012, 11:40 PM
  4. Complex Numbers in Java
    By JavaNovice03355 in forum Member Introductions
    Replies: 1
    Last Post: May 18th, 2011, 07:30 PM
  5. Can anyone help analyze these java dumps for Windows ?
    By ansonxiaoshun in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 16th, 2011, 01:27 AM