title: Why is my stack overflowing when I push less data through it?
body: <p>I am working on creating a weighted US map and I have broken the zip codes down into 3 digit zip zones. I then use a for loop that iterates 1000 times to color each 3 digit zip zone a random color.</p>
  
  <p>This works every time with out issue. My current issue is coming in if I start my for loop count above 310. Anything less than 310 and it loops through perfectly. So since raising the initial count would mean that it would run the recursive code less, then this does make any sense to me.</p>
  
  <p>The code that calls the for loop:</p>
  
  <pre><code>private void GUI()
  {       
      JFrame frame = new JFrame();
      frame.setLayout(new MigLayout());
  
      try
      {
          mapImg = ImageIO.read(new File("Res/Zipzone map of the US.png"));
      } 
      catch (IOException e) 
      {
          e.printStackTrace();
      }
      g = mapImg.createGraphics();
  
      for(int i = 311; i &lt; 1001; i++)
      {
          Random rand = new Random();
          String count = "";
          int red = rand.nextInt(220) + 25;
          int green = rand.nextInt(220) + 25;
          int blue = rand.nextInt(220) + 25;
          if(i &lt; 100)
          {
              count = "0" + i;
          }
          else
          {
              count = i + "";
          }
          if(i &lt;= 512)
          {
              ApplyColor(count, new Color(red, blue, green));
          }
          else if( i &gt; 909)
          {
              ApplyColor3(count, new Color(red, blue, green));
          }
          else
          {
              ApplyColor2(count, new Color(red, blue, green));
          }
      }
  
      frame.add(new JLabel("", new ImageIcon(GetScaledImage(new ImageIcon(mapImg).getImage(), 1400, 875)), JLabel.CENTER), "GROW, PUSH");
      frame.setTitle("US Map");
      frame.setSize(1500,900);
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
  }
  </code></pre>
  
  <p>Small example of the apply color function:</p>
  
  <pre><code>private void ApplyColor(String zip, Color color)
  {
      int x;
      int y;
      if(zip.equals("010"))
      {
          try
          {
              x = 3339;
              y = 672;
              FloodFill(x, y, new Color(mapImg.getRGB(x, y)), color);
              x = 3361;
              y = 681;
              FloodFill(x, y, new Color(mapImg.getRGB(x, y)), color);
          }
          catch(AWTException e)
          {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>And the FloodFill function:</p>
  
  <pre><code>public void FloodFill(int x, int y, Color targetColor, Color replacementColor) throws AWTException
  {
      if(new Color(mapImg.getRGB(x, y)).equals(replacementColor))
      {
          return;
      }
  
      g.setColor(replacementColor);
      g.fillRect(x, y, 1, 1);
  
      if(new Color(mapImg.getRGB(x-1, y)).equals(targetColor))
      {
          FloodFill(x-1, y, targetColor, replacementColor);
      }
  
      if(new Color(mapImg.getRGB(x+1, y)).equals(targetColor))
      {
          FloodFill(x+1, y, targetColor, replacementColor);
      }
  
      if(new Color(mapImg.getRGB(x, y-1)).equals(targetColor))
      {
          FloodFill(x, y-1, targetColor, replacementColor);
      }
  
      if(new Color(mapImg.getRGB(x, y+1)).equals(targetColor))
      {
          FloodFill(x, y+1, targetColor, replacementColor);
      }
  }
  </code></pre>