Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: will continue later

...

Code Block
bgColor#ccccff
class ShowHeapError {
  // ... other methods

  static public String readLimitedLine(Reader reader, int limit) throws IOException {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < limit; i++) {
      int c = reader.read();
      if (c == -1) {
        return null;
      }
      if (((char) c == '\n') || ((char) c == '\r')) {
        break;
      }
      sb.append((char) c);
    }
    return sb.toString();
  }

  static public final int lineLengthLimit = 1024;
  static public final int lineCountLimit = 1000000;

  public void addNames() throws IOException {
    try {
      String newName;
      for (int i = 0; i < lineCountLimit; i++) {
        newName = readLimitedLine( reader, lineLengthLimit);
        if (newName == null) {
          break;
        }
        if ( || newName.equalsIgnoreCase("quit")) {
          break;
        }

        names.addElement(newName);
        System.out.println("adding " + newName);
      }
    } finally {
      input.close();
    }
  }

}

...

Code Block
bgColor#ccccff
class ShowHeapError {
  static public final int fileSizeLimit = 1000000;

  public ShowHeapError(String filename) throws IOException {
    if (Files.size( Paths.get( filename)) > fileSizeLimit) {
      throw new IOException("File too large");
    }
    this.input = new FileReader(filename);
    this.reader = new BufferedReader(input);
  }

  // ...other methods
}

...

Wiki Markup
The {{OutOfMemoryError}} can be avoided by ensuring that the absence of infinite loops, memory leaks, and unnecessary object retention. When memory requirements are known ahead of time, the heap size can be tailored to fit the requirements using the following runtime parameters \[[Java 2006|AA. Bibliography#Java 06]\]:

...

CERT C Secure Coding Standard

MEM11-C. Do not assume infinite heap space

CERT C++ Secure Coding Standard

MEM12-CPP. Do not assume infinite heap space

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d5db3042b2d59373-a054abde-442d4d49-967cb6dd-33f884bd73b3dd15af3348dd"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

"Resource Exhaustion [XZP]"

]]></ac:plain-text-body></ac:structured-macro>

MITRE CWE

CWE-400, "Uncontrolled Resource Consumption ('Resource Exhaustion')"

 

CWE-770, "Allocation of Resources Without Limits or Throttling"

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1efd74b56cde9fd2-ce8504ad-4ede4fbb-9077b603-ad560b835540332462d6db19"><ac:plain-text-body><![CDATA[

[[Sun 2006

AA. Bibliography#Sun 06]]

[Garbage Collection Ergonomics

http://java.sun.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html ], "Default values for the Initial and Maximum heap size"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e6d7116a711ca41d-f23a0562-48a44994-b021bafa-462355ff1f85cb08742ae433"><ac:plain-text-body><![CDATA[

[[Java 2006

AA. Bibliography#Java 06]]

[java - the Java application launcher

http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html ], "Syntax for increasing the heap size"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="aa5d880b6ad11b8d-1cf54c7c-49f64b2c-979aaca1-072355222a6e6dc978adbaf9"><ac:plain-text-body><![CDATA[

[[Sun 2003

AA. Bibliography#Sun 03]]

Chapter 5: Tuning the Java Runtime System, [Tuning the Java Heap

http://docs.sun.com/source/817-2180-10/pt_chap5.html#wp57027]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b7e0f70a5d5aee48-d8a9465d-4f1a43a3-b9aa8a7c-30d51c8ece5ec46091aa0f72"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

Class ObjectInputStream and ObjectOutputStream

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="53563d60c7fe66f3-cbe0518d-430b4702-8a5d9fa3-5ffc0b9b4192deafc9055c28"><ac:plain-text-body><![CDATA[

[[SDN 2008

AA. Bibliography#SDN 08]]

[Serialization FAQ

http://java.sun.com/javase/technologies/core/basic/serializationFAQ.jsp]

]]></ac:plain-text-body></ac:structured-macro>

...