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 4 of 4

Thread: Denial of Service and null pointer

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Location
    Amsterdam
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Denial of Service and null pointer

    Hi,

    I have written a socket program which read HTTP post message, my programe works fine but I get code quality issue. i get 8 defects in one line of code. Not able to fix .Below is my code.
    try (Socket httpSocket = server.accept();
    	BufferedReader reader = new BufferedReader(new InputStreamReader(httpSocket.getInputStream(),"UTF8"),2048);
    	BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(httpSocket.getOutputStream(),"UTF8"),2048);  ) 
    {			
    	httpSocket.setSoTimeout(600);
    	reader.ready();
          [B]  line = reader.readLine();[/B] //get null pointer and denial of service
            isPost = line.startsWith("post"); 
            int contentLength = 0;
            while (!(line = reader.readLine()).equals("")) {
                if (isPost) {
                    final String contentHeader = "Content-Length: ";
                    if (line.startsWith(contentHeader)) {
                        contentLength = Integer.parseInt(line.substring(contentHeader.length()));
                    }
                }
            }
    }
    I get following observation in Fortify
    1) Denial of service at (line = reader.readLine(); ) and line = reader.readLine()).equals("")
    2) Missing Check against Null at (line = reader.readLine(); ) and line = reader.readLine()).equals("")
    Sonar Voilation
    1) Remove this use of constructor "InputStreamReader(InputStream)"
    2) Remove this use of constructor "OutputStreamWriter(OutputStream)"


    Regards
    Sandeep Shukla
    Last edited by shuklasan78; January 22nd, 2018 at 10:08 AM. Reason: Moved ) to prevent smiley

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Denial of Service and null pointer

    i get 8 defects in one line of code.
    Please explain.
    If there are any error messages, copy the full text and paste it here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    shuklasan78 (January 22nd, 2018)

  4. #3
    Junior Member
    Join Date
    Dec 2017
    Location
    Amsterdam
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Denial of Service and null pointer

    thanks Norm, I have done the needful. I do not have any error, I am just trying to fix the issue of Fortify and Sonar code quality
    I get following observation in Fortify
    1) Denial of service at (line = reader.readLine(); ) and line = reader.readLine()).equals("")
    2) Missing Check against Null at (line = reader.readLine(); ) and line = reader.readLine()).equals("")
    Sonar Voilation
    1) Remove this use of constructor "InputStreamReader(InputStream)"
    2) Remove this use of constructor "OutputStreamWriter(OutputStream)"

    Regards
    Sandeep Shukla

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Denial of Service and null pointer

    Fortify and Sonar code
    Sorry, I have no idea what that means.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Null Pointer Exception. Why?
    By popnfresh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 5th, 2013, 12:06 PM
  2. Need Help with Null Pointer Exception
    By kendraheartt in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 23rd, 2012, 02:20 PM
  3. Null Pointer exception
    By Demetrius82 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 2nd, 2011, 07:32 PM
  4. [SOLVED] Null Pointer Exception
    By musasabi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 11th, 2010, 09:25 PM
  5. Null pointer exception
    By Wrathgarr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2010, 12:48 AM

Tags for this Thread