{"record":{"id":"2b5da43c27752bf6","repo":"libgdx/libgdx","slug":"nullpointerexception","errorCode":null,"errorMessage":"NullPointerException","messagePattern":"NullPointerException","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatBuffer.java","lineNumber":74,"sourceCode":"\t\treturn wrap(array, 0, array.length);\n\t}\n\n\t/** Creates a new float buffer by wrapping the given float array.\n\t * <p>\n\t * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the\n\t * array.\n\t * </p>\n\t * \n\t * @param array the float array which the new buffer will be based on.\n\t * @param start the start index, must not be negative and not greater than {@code array.length}.\n\t * @param len the length, must not be negative and not greater than {@code array.length - start}.\n\t * @return the created float buffer.\n\t * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.\n\t * @exception NullPointerException if {@code array} is null.\n\t * @since Android 1.0 */\n\tpublic static FloatBuffer wrap (float[] array, int start, int len) {\n\t\tif (array == null) {\n\t\t\tthrow new NullPointerException();\n\t\t}\n\t\tif (start < 0 || len < 0 || (long)start + (long)len > array.length) {\n\t\t\tthrow new IndexOutOfBoundsException();\n\t\t}\n\n\t\tFloatBuffer buf = BufferFactory.newFloatBuffer(array);\n\t\tbuf.position = start;\n\t\tbuf.limit = start + len;\n\n\t\treturn buf;\n\t}\n\n\t/** Constructs a {@code FloatBuffer} with given capacity.\n\t * \n\t * @param capacity The capacity of the buffer */\n\tFloatBuffer (int capacity) {\n\t\tsuper(capacity);\n\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatBuffer.java#L56-L92","documentation":"Thrown by FloatBuffer.wrap(float[] array, int start, int len) when array is null — the null check precedes all index validation, per the documented NullPointerException. wrap(float[]) (single-arg) delegates here with 0/array.length, so a null array fails identically. The buffer would wrap the array directly (no copy), hence null is rejected up front.","triggerScenarios":"Calling FloatBuffer.wrap(null) or wrap(nullArray, 0, 0); passing a lazily-initialized field that was never assigned; a data-source method returning null (optional/absent data) piped straight into wrap().","commonSituations":"Optional mesh attributes (e.g. missing color array) modeled as null in asset loaders; map.get(key) results used without a null check before wrapping; refactoring that changed a supplier's contract from empty-array to null-on-empty.","solutions":["Null-check before wrapping: if (arr == null) arr = EMPTY_FLOATS; (a shared zero-length array) or branch on null and skip the buffer entirely.","Fix the producer to return float[0] instead of null for absent data, making the empty case uniform.","Where null is meaningful, handle it at the call site with an explicit decision (default buffer, error) rather than letting wrap() throw."],"exampleFix":"// before\nfloat[] colors = meshData.getColors(); // null when absent\nFloatBuffer cb = FloatBuffer.wrap(colors); // NullPointerException\n\n// after\nfloat[] colors = meshData.getColors();\nFloatBuffer cb = (colors == null) ? FloatBuffer.allocate(0) : FloatBuffer.wrap(colors);","handlingStrategy":"validation","validationCode":"FloatBuffer safeWrap(float[] arr) {\n    return arr == null ? FloatBuffer.allocate(0) : FloatBuffer.wrap(arr);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make producers return float[0] instead of null for absent data.","Null-check optional attribute arrays before wrapping.","Use a shared EMPTY_FLOATS constant for the empty case."],"tags":["nio","buffer","gwt","libgdx","java","null-safety"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}