9 Replies Latest reply: Apr 15, 2014 2:29 PM by EJP RSS

    memory leaking?

    Hjava

      does the following code can cause the memory leaking ?

      String[] rows = req.getParameterValues("t_count");

                          if (rows == null && rows.length==0) {

       

       

      errormessage}esle{

      insert , update and delete

      }

       

       

       

      <tr><td>

      <input name='t_count' maxlength='5' size='2' type='hidden' value='" + rs.getString("St_id") + "' />

      </td></tr>

        • 1. Re: memory leaking?
          jwenting

          no, it will never leak anything.

          To leak memory first it has to run, and this code will never compile so isn't going to run.

          • 2. Re: memory leaking?
            Hjava

            The else is work , why you said is not run?

            the if is not , I just realize the following code is dramatic , it may have over 40 rows, it may have 0 rows. on this situation, how to write the if ?

            <input name='t_count' maxlength='5' size='2' type='hidden' value='" + rs.getString("St_id") + "' />
            • 3. Re: memory leaking?
              EJP

              <> Why you said it not run?

               

              Because if rows == null, evaluating rows.length will cause a NullPointerException. It doesn't make sense to test that if rows == null, only if it isn't. And why you expect HTML code in the middle of a Java class to compile is another mystery.

              • 4. Re: memory leaking?
                gimbal2

                Puzzling indeed, even it is a poorly written JSP I'm missing <%= %> scriptlet tags.

                 

                But obviously it is not the code that has problems, its just a quickly tossed together example that is chopped up so badly it is a criminal offense.

                • 5. Re: memory leaking?
                  jwenting

                  and why does he expect this

                   

                  errormessage}esle{
                  insert , update and delete
                  }
                  

                   

                  to be valid Java code?

                  • 6. Re: memory leaking?
                    Hjava

                    Hi EJP,

                    you are right on , under this situation, is that a way on java to if the row did not exist , message out?

                    Because if rows == null, evaluating rows.length will cause a NullPointerException. It doesn't make sense to test that if rows == null, only if it isn't.

                    is Servlet, there is some old project did not use jsp or jstl, you have to learn  how put html. css code inside the servlet, is not my choose

                    you expect HTML code in the middle of a Java class to compile is another mystery.
                    • 7. Re: memory leaking?
                      EJP

                      > is that a way on java to if the row did not exist , message out?

                       

                      Please restate your question in standard English.

                       

                      > is Servlet, there is some old project did not use jsp or jstl, you have to learn  how put html. css code inside the servlet, is not my choose

                       

                      Ditto. I can't make head or tail of most of this, but your page is almost certainly a JSP, whether you're aware of it or not.

                      • 8. Re: memory leaking?
                        Hjava

                        1) I don't want the NullPointerException, I want some error message

                        Because if rows == null, evaluating rows.length will cause a NullPointerException. It doesn't make sense to test that if rows == null, only if it isn't.


                        2) we have html code inside the servlet

                        • 9. Re: memory leaking?
                          EJP

                          1. So fix your code. I've told you what's wrong with it. I'd even tell you how to fix it but you haven't provided enough of it for anyone to know what it supposed to be doing,

                          2. Could be anything. All I see is incomplete code that doesn't compile.