diff --git a/java/src/main/java/tech/sourced/enry/GoUtils.java b/java/src/main/java/tech/sourced/enry/GoUtils.java index 3deb6f4..4168aca 100644 --- a/java/src/main/java/tech/sourced/enry/GoUtils.java +++ b/java/src/main/java/tech/sourced/enry/GoUtils.java @@ -58,7 +58,7 @@ class GoUtils { static GoSlice.ByValue toGoByteSlice(byte[] bytes) { int length = 0; Pointer ptr = null; - if (bytes != null) { + if (bytes != null && bytes.length > 0) { length = bytes.length; ptr = ptrFromBytes(bytes); } diff --git a/java/src/test/java/tech/sourced/enry/EnryTest.java b/java/src/test/java/tech/sourced/enry/EnryTest.java index 0b599c5..9a1a453 100644 --- a/java/src/test/java/tech/sourced/enry/EnryTest.java +++ b/java/src/test/java/tech/sourced/enry/EnryTest.java @@ -23,6 +23,12 @@ public class EnryTest { assertEquals("Python", Enry.getLanguage("foo.py", null)); } + @Test + public void getLanguageWithEmptyContent() { + assertEquals("Go", Enry.getLanguage("baz.go", "".getBytes())); + assertEquals("Go", Enry.getLanguage("baz.go", null)); + } + @Test public void getLanguageWithNullFilename() { byte[] content = "#!/usr/bin/env python".getBytes();