tsantalis / JDeodorant

JDeodorant
https://marketplace.eclipse.org/content/jdeodorant
MIT License
139 stars 59 forks source link

NPE : FasterXML/jackson-core Long Method Refactoring #57

Closed feroozkhanchintu closed 8 years ago

feroozkhanchintu commented 8 years ago

Project : FasterXML/jackson-core (https://github.com/FasterXML/jackson-core) Package : com.fasterxml.jackson.core.json.WriterBasedJsonGenerator Method : private void _writeSegmentCustom(int) throws java.io.IOException Variable consideration : _writer Block : B2

java.lang.NullPointerException
at gr.uom.java.jdeodorant.refactoring.manipulators.ExtractMethodRefactoring.modifySourceMethod(ExtractMethodRefactoring.java:222)
    at gr.uom.java.jdeodorant.refactoring.manipulators.ExtractMethodRefactoring.apply(ExtractMethodRefactoring.java:147)
    at gr.uom.java.jdeodorant.refactoring.manipulators.ExtractMethodRefactoring.checkFinalConditions(ExtractMethodRefactoring.java:382)
tsantalis commented 8 years ago

Loop while (ptr < end) is nested under label output_loop: Special handling for labeled statements is needed to fix the NullPointerException

output_loop:
while (ptr < end) {
    // Fast loop for chars not needing escaping
    char c;
    while (true) {
        c = _outputBuffer[ptr];
        if (c < escLimit) {
            escCode = escCodes[c];
            if (escCode != 0) {
                break;
            }
        } else if (c > maxNonEscaped) {
            escCode = CharacterEscapes.ESCAPE_STANDARD;
            break;
        } else {
            if ((_currentEscape = customEscapes.getEscapeSequence(c)) != null) {
                escCode = CharacterEscapes.ESCAPE_CUSTOM;
                break;
            }
        }
        if (++ptr >= end) {
            break;
        }
    }
    int flushLen = (ptr - start);
    if (flushLen > 0) {
        _writer.write(_outputBuffer, start, flushLen);
        if (ptr >= end) {
            break output_loop;
        }
    }
    ++ptr;
    start = _prependOrWriteCharacterEscape(_outputBuffer, ptr, end, c, escCode);
}