diff --git a/java/src/main/java/tech/sourced/enry/GoUtils.java b/java/src/main/java/tech/sourced/enry/GoUtils.java index 3deb6f44..4168aca1 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 @@ static String[] toJavaStringArray(GoSlice slice) { 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 0b599c58..9a1a4539 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 void getLanguageWithNullContent() { 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();