# Thread: Found a bug, need others to confirm.

1. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Found a bug, need others to confirm.

Hi all, new to forums. This problem is the only reason I'm here, but I can see myself being a frequent visitor if you guys can help :)
I've been programming in java for about 6 years now.

Anyways here is it:
I have a 2d array of size [35][100] called "rain", all holding boolean values.
In this method is the problem. lines 3 and 4 may be disregarded.
Java Code:
```/* 1*/public void collision()
/* 2*/	{
/* 3*/		int startX = (int)Math.round((Math.round(boxX) - boxXmin)/2);
/* 4*/		int endX = startX+13;
/* 5*/		for(int y = 2; y <= 14;y++)
/* 6*/		{
/* 7*/			for(int x = startX;x < endX; x++)
/* 8*/			{
/* 9*/				if(rain[y][x] == true)
/*10*/				{
/*11*/					rain[y][x] = false;
/*12*/				}
/*13*/			}
/*14*/
/*15*/		}
/*16*/	}```
for debugging i have a breakpoint at line 5. when the program halts at that line rain[0][0-99], rain[1][0-99] and rain[2][0-99] are all true.
i step down to line 9. check value of y, it is 2. check value of x, it is 47. check the first three sets of rain (rain[0-3]) all true still.
if statement is true as expected. at line 11 I check values of x, y and the first 3 sets of rain again, still all the same.
step down again, line 11 executes. rain[2][47] is now false, as expected, BUT rain[1][47] AND rain[0][47] went false as well!
as i finish the inner for loop it does the same for all x's.

Ive been looking at this for hours and have no idea. I've come to the conclusion its a bug, rain[y][x] = false; should set that one value to false and that one only, not three of them!

2. Senior Member
Join Date
Feb 2011
Location
Georgia, USA
Posts
122
Rep Power
0

## Re: Found a bug, need others to confirm.

Are you wanting the loops to stop after the first true value it finds? The way you have it setup, it will just run until it has met the stopping condition in each of the loops and set all true values it finds to false.

3. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

no i do want it to go through the loops no matter what happens in the if statement.
the problem is that once the if statement gets executed the first time the data in rain[0] and rain[1] gets changed and that should not be possible at all.
Maybe i should make a vid of me debugging it and show u exactly whats happening

4. Senior Member
Join Date
Feb 2011
Location
Georgia, USA
Posts
122
Rep Power
0

## Re: Found a bug, need others to confirm.

I personally would write a method that prints the whole rain matrix and call it right before the loop and right after the loop to see what is going on. Then compare the two to see what is happening. The value of y in that loop will never be 0 or 1 so I don't see how that portion of your code could change the values in rain[0][x] or rain[1][x] at all. Are you sure nothing else is going on?

Also, I don't understand the purpose of the if statement. In the end every value touched in that loop will be false, why not just get rid of the if statement and set the value to false.

5. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

rain is used to draw rain drops on a JPanel, so i do have a visual representation of whats going on.
The purpose of the if statement is because later ill need to keep track of how many were changed to false so inside the if statement is where the counter will be incremented.
And that is exactly my point, y is never 0 yet is does change those values. I am positive that nothing else is changing it, in debugging i witnessed that values of rain[0][x] and rain[1][x] being true, and RIGHT after rain[2][x] = false gets executed the others get changed to false as well.
I need to go figure out how to record my screen and show u guys this black magic.

6. Senior Member
Join Date
Feb 2011
Location
Georgia, USA
Posts
122
Rep Power
0

## Re: Found a bug, need others to confirm.

strange. Is the rain array filled with boolean primitives or Boolean objects? Maybe it is a referencing issue?

I seriously doubt it is a bug in Java because everything you posted are constructs that have used and tested over and over.

7. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14

## Re: Found a bug, need others to confirm.

Is the rain array filled with boolean primitives or Boolean objects?
I wondered about that. But it makes no difference.

In the code posted y never has the values 0 or 1, so "rain[y][x]=false;" never sets the value of rain[0][47]. The observed change doesn't happen.

I think what's needed here is a SSCCE, perhaps with the array printed before and after as yellowledbet suggests, or some other metric like counting the changes. Something along the lines of

Java Code:
```public class Foo {
public static void main(String[] args) {
final int SZ = 100;
boolean[][] rain = new boolean[SZ][SZ];
//Boolean[][] rain = new Boolean[SZ][SZ];
for(int y = 0; y < SZ; y++) {
for(int x = 0; x < SZ; x++) {
rain[y][x] = true;
}
}

int startX = 47;
int endX = startX + 13;
int changed = 0;

for(int y = 2; y <= 14;y++) {
for(int x = startX;x < endX; x++) {
if(rain[y][x]) { // nicer than if(whatever==true)...
rain[y][x] = false;
changed++;
}
}
}

// expecting 13*13=169
System.out.println("There were " + changed + " changes");

// expecting "true"
System.out.println("rain[0][47]=" + rain[0][47]);
}
}```
This would be a good SSCCE except for the fact that we get exactly the output we expect...
Last edited by pbrockway2; 03-25-2012 at 01:11 AM.

8. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14

## Re: Found a bug, need others to confirm.

A couple of things I forgot...

First you can post images, or links to photosharing sites. Or describe context of the debugger. As it stands I don't think anyone can comment sensibly on what might be seen with a debugger (we don't know which) configured in some way (we don't know how) running code (of which we have a snippet). Failing that we are left considering the claim that "rain[y][x] = false;" is setting three array element values which would indicate a bug with either how Oracle implements the assignment operator, or how they implement arrays, both of which are vanishingly unlikely.

Also my attempt at a SSCCE declares rain which your collision() method does not. I mention this because it allows the possibility that there are threads involved in the case. Tangling things up.

9. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

I've done lots of debugging and narrowed it down to 1 line of code. the one in the if statement.

also, i can show u guys the whole code if it would help.

10. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14

## Re: Found a bug, need others to confirm.

I don't see this with the code I posted. Ie running to the inner for loop line twice, the expression inspector shows rain[2][47] false and rain[0][47] true. (Indigo Service Release 1).

I'd put my money on threads. The top of the screen (most clearly visible at the start of the video) shows multiple threads running. You might want to try with a single thread.

11. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

the other thread is my engine. all it does is call update() collision() and draw() in the class where im having a problem.
ill try doing that within the same thread, but i dont see how the second thread has anything to do with what happens in rain[][]

12. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14

## Re: Found a bug, need others to confirm.

i dont see how the second thread has anything to do with what happens in rain[][]
What your video shows is that some time between the assignment line occurring and the inner for loop line about to occur there is a change to the value of rain[0][47]. It does not show that the assignment line caused the assignment of false to rain[0][47]. That second assignment occurs for whatever reason it occurs: the reason being currently unknown and highly unlikely to be a bug in Oracle's implementation of assignment or arrays. (or, for that matter, Eclipse's debugger. I did do a search for that...)

Now if, in some other thread, the engine is calling update(), collision() - again -, or draw() then there is nothing to stop those methods altering the contents of the rain array. Or some other thread again, created by them, from doing so. As an example - purely hypothetical - update() could whip through the array and when it finds a value false at some position it might set the array entries for smaller y values (and the corresponding x value) to false as well. This might be its idea of updating and, if so, it would cause the behaviour you have seen.

I guess what I'm saying is that something is causing the array entries to change and that something is what you have to find. Nothing in the code or the video shows that the assignment "rain[y][x]=false;" is the proximate cause of that change. And common sense suggests that it is not.

13. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

Eliminated the other thread completely. it all now is a single java file and the problem persists. Same problem, same line of code.
I have no ideas, anyone can help? please

14. ## Re: Found a bug, need others to confirm.

So where's that SSCCE?

Oh, and after 6 years of Java do you really write code like this?
Java Code:
`if(rain[y][x] == true)`
That should be
Java Code:
`if(rain[y][x])`
db

15. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

o.. yea about the "== true", i don't know what i was thinking, lol.

And i coulda sworn i put up the code already, i don't know what happened to it. Sorry.
the rain instantiation gets cut off but it should still allow you to select it all.

Java Code:
```import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Simulator //extends Engine
{
private int frameWidth = 407;
private int frameHeight = 279;
private int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
private int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
private JFrame myFrame = new JFrame();
private final int FPS = 2;
private final long framePeriod = (1000 / FPS) * 1000000L;
private boolean l = true;
private boolean O = false;
private boolean rain[][] = {{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l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,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//31
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//32
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//33
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//34
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l}};//35

private int dropSize = 3 - 1;
private int dropSwitch = 0;
private float boxX = 101.0f;
private int boxXmin = 11;
private int boxXmax = 185;
private float boxXvel = 1.0f;
private int dropsHit = 0;
private int averageDrops[] = {0,0,0,0,0,0,0,0,0,0};
private int averageIndex = 0;

public Simulator() throws InterruptedException
{
myFrame.setTitle("Rain Simulator");
myFrame.setSize(frameWidth, frameHeight);
myFrame.setLocation((screenWidth - frameWidth)/2, (screenHeight - frameHeight)/2);
myFrame.setDefaultCloseOperation(3);
myFrame.setResizable(false);
myFrame.setLayout( new BorderLayout());
myFrame.setIgnoreRepaint(true);

JPanel leftPanel = new JPanel();
JPanel centerPanel = new MainPanel();
JPanel bottomPanel = new JPanel();

bottomPanel.setPreferredSize(new Dimension(500, 50));
leftPanel.setPreferredSize(new Dimension(100, 350));
myFrame.setVisible(true);

engine();
}

private class MainPanel extends JPanel
{
MainPanel()
{
super();
}

public void paintComponent(Graphics g)
{
g.setColor(Color.WHITE);
g.fillRect(0, 0, 300, 200);
g.setColor(Color.BLACK);
g.drawRect(0, 0, 300, 200);

g.setColor(Color.BLUE);
for(int y2 = 0; y2 < 55; y2++)
{
for(int x2 = 0; x2 < 100; x2++)
{
}
}
for(int y1 = 0; y1 < 35; y1++)
{
for(int x1 = 0; x1 < 100; x1++)
{
if(rain[y1][x1])
{
}
}
}

g.setColor(Color.BLACK);
g.drawRect(10, 10, 200, 181);
g.drawRect(220, 10, 70, 181);
g.fillRect(10, 150, 200, 2);
g.fillRect(220, 150, 70, 2);
g.setColor(Color.ORANGE);
g.fillRect((int)Math.round(boxX), 125, 25, 25);
g.fillRect(242, 125, 25, 25);
}
}

public void update()
{
dropSwitch = (dropSwitch+1)%2;
if(dropSwitch == 0)
{
for(int i = 34; i > 0; i--)
{
rain[i] = rain[i-1];
}
}
boxX += boxXvel;
if(boxX > boxXmax)
{
boxX = 2*boxXmax - boxX;
boxXvel *= -1;
}
if(boxX < boxXmin)
{
boxX = 2*boxXmin - boxX;
boxXvel *= -1;
}
}

public void collision()
{
int startX = (int)Math.round((Math.round(boxX) - boxXmin)/2);
int endX = startX+13;
dropsHit = 0;
for(int y = 2; y <= 14;y++)
{
for(int x = startX;x < endX; x++)
{
if(rain[y][x])
{
rain[y][x] = false;
dropsHit++;
}
}
}
}

public void draw()
{
myFrame.repaint();
}

public void engine() throws InterruptedException
{
long beforeTime, afterTime, timeDiff, sleepTime;
while(true)
{
beforeTime = System.nanoTime();
update();
collision();
draw();
afterTime = System.nanoTime();
timeDiff = afterTime - beforeTime;
sleepTime = framePeriod - timeDiff;
if(sleepTime > 0)
{
}
}
}

public static void main(String[] args) throws InterruptedException
{
Simulator s = new Simulator();
}
}```
Last edited by SergeLo; 03-27-2012 at 10:54 AM.

16. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

Tried making rain[][] hold integers (0 for false, 1 for true).

17. ## Re: Found a bug, need others to confirm.

That's no SSCCE. Your claim was that assigning a value to one array element was affecting other elements of the same 2D array. All the GUI stuff is just clutter. Take a look at the code posted by pbrockway2 at #7 -- that's a SSCCE.

And Swing constructors and methods should be invoked on the EDT, not on the main thread.

db

18. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

Sorry I have been a lil busy with midterms.
I left the GUI in as the display of the rain array, but if its clutter then that fine, ill take it out.
I needed to leave the engine method in because my problem starts happening in the 2nd run through the collision method.
After removing more stuff I checked and made sure the problem still persists.

Thank you for your guys' help so far, I do appreciate it.
Hopefully you like this better, its half as long:
Java Code:
```public class Simulator
{
private final int FPS = 2;
private final long framePeriod = (1000 / FPS) * 1000000L;
private boolean l = true;
private boolean O = false;
private boolean rain[][] = {{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//1
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l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,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//32
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//33
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l},//34
{l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,O,O,O,O,O,O,O,O,O,O,O,O,O,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l}};//35

private float boxX = 101.0f;
private int boxXmin = 11;
private float boxXvel = 1.0f;
private int dropsHit = 0;

public Simulator() throws InterruptedException
{
engine();
}

public void update()
{
for(int i = 34; i > 0; i--)
{
rain[i] = rain[i-1];
}

boxX += boxXvel;
}

public void collision()
{
int startX = (int)Math.round((Math.round(boxX) - boxXmin)/2);
int endX = startX+13;
dropsHit = 0;
for(int y = 2; y <= 14;y++)
{
for(int x = startX;x < endX; x++)
{
if(rain[y][x])
{
rain[y][x] = false;
dropsHit++;
}
}
}
System.out.println(dropsHit);
}

public void engine() throws InterruptedException
{
long beforeTime, afterTime, timeDiff, sleepTime;
while(true)
{
beforeTime = System.nanoTime();
update();
collision();
afterTime = System.nanoTime();
timeDiff = afterTime - beforeTime;
sleepTime = framePeriod - timeDiff;
if(sleepTime > 0)
{
}
}
}

public static void main(String[] args) throws InterruptedException
{
Simulator s = new Simulator();
}
}```

19. Member
Join Date
Mar 2012
Posts
13
Rep Power
0

## Re: Found a bug, need others to confirm.

So I decided to see what happens when i keep a counter of how many "true" values i have in the rain array by looping through the whole thing before the for loop, and then again after the for loop, and finally compare the results to the number of drops hit which is calculated inside the for loop.
Here is the code and results. Sure enough things aren't adding up... :\

Java Code:
```dropsHit = 0;
trueCounterBefore = 0;
for(int ay = 0; ay <= 34;ay++)
{
for(int ax = 0;ax <= 99; ax++)
{
if(rain[ay][ax])
{
trueCounterBefore++;
}
}
}
for(int y = 2; y <= 14;y++)
{
for(int x = startX;x < endX; x++)
{
if(rain[y][x])
{
rain[y][x] = false;
dropsHit++;
}
}
}
trueCounterAfter = 0;
for(int by = 0; by <= 34;by++)
{
for(int bx = 0;bx <= 99; bx++)
{
if(rain[by][bx])
{
trueCounterAfter++;
}
}
}
System.out.println("Before Trues: " + trueCounterBefore);
System.out.println("After Trues:  " + trueCounterAfter);
System.out.println("Before/After Difference: " + (trueCounterBefore-trueCounterAfter));
System.out.println("Drops Hit: " + dropsHit);```
Output for a few seconds:
Before Trues: 3084
After Trues: 3071
Before/After Difference: 13
Drops Hit: 13
Before Trues: 3084
After Trues: 3033
Before/After Difference: 51
Drops Hit: 25
Before Trues: 3033
After Trues: 3033
Before/After Difference: 0
Drops Hit: 0
Before Trues: 3033
After Trues: 3018
Before/After Difference: 15
Drops Hit: 11
Before Trues: 3017
After Trues: 3017
Before/After Difference: 0
Drops Hit: 0
Before Trues: 3016
After Trues: 3001
Before/After Difference: 15
Drops Hit: 9
Before Trues: 2999
After Trues: 2999
Before/After Difference: 0
Drops Hit: 0
Before Trues: 2997
After Trues: 2982
Before/After Difference: 15
Drops Hit: 7

Number of drops hit and the before/after difference should always be the same, yet its not.

P.S. the zeros come up every other time because the drop sizes are 2x2 while they drop by 1 each cycle. So when they hit the box they go away, leaving a row of pixels above the box blank and therefore 0 hits occur next cycle. //this isnt the problem
Last edited by SergeLo; 04-03-2012 at 04:11 AM.

20. Senior Member
Join Date
Feb 2011
Location
Georgia, USA
Posts
122
Rep Power
0

## Re: Found a bug, need others to confirm.

I am not 100% percent sure what you are trying to do but I think it may be a referencing issue. Try to update your update() method with below code. That is my best geuss

Java Code:
```public void update()
{
for(int i = 34; i > 0; i--)
{
rain[i] = Arrays.copyOf(rain[i-1], rain[i-1].length);
}

boxX += boxXvel;
}```

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•