Skip to content

Commit b5ec183

Browse files
authored
serialization: handle 'null' value from java's File.getParent api (#291)
`java.nio.Path::getParent` returns `null` if the path is the root directory already, so trying to create the root's parent directory both fails hard and doesn't make any sense
1 parent c6b0cbc commit b5ec183

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

core/src/main/scala/flatgraph/storage/Serialization.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ object Serialization {
2020
val stringPool = mutable.LinkedHashMap[String, Int]()
2121

2222
// ensure parent directory exists
23-
val parentDir = storagePath.getParent
24-
if (Files.notExists(parentDir)) Files.createDirectories(parentDir)
23+
Option(storagePath.getParent) match {
24+
case Some(dir) => if (Files.notExists(dir)) Files.createDirectories(dir)
25+
case None => // no parent, i.e. we're at the root dir already
26+
}
2527

2628
val fileChannel =
2729
new java.io.RandomAccessFile(storagePath.toAbsolutePath.toFile, "rw").getChannel

core/src/test/scala/flatgraph/SerializationTests.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package flatgraph
22

3-
import flatgraph.TestSchema.testSerialization
43
import flatgraph.misc.DebugDump.debugDump
54
import flatgraph.storage.{Deserialization, Serialization}
65
import org.scalatest.matchers.should.Matchers

0 commit comments

Comments
 (0)