-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stackoverflow for scala traits (#9)
* Integration test for transitively Serializable objects * Fix StackoverflowError for scala traits * Up version to 1.4.1
- Loading branch information
Showing
12 changed files
with
53 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,5 @@ allprojects { | |
} | ||
|
||
group 'me.shika' | ||
version '1.4.0' | ||
version '1.4.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
apply plugin: "org.jetbrains.kotlin.jvm" | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
implementation project('scala-module') | ||
testImplementation 'junit:junit:4.12' | ||
|
||
kotlinCompilerPluginClasspath project(':kotlin-plugin') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id 'scala' | ||
id 'java-library' | ||
} | ||
|
||
dependencies { | ||
api 'org.scala-lang:scala-library:2.12.17' | ||
} |
1 change: 1 addition & 0 deletions
1
integration-test/scala-module/src/main/scala/NotSerializableTrait.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
trait NotSerializableTrait |
1 change: 1 addition & 0 deletions
1
integration-test/scala-module/src/main/scala/SerializableTrait.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
trait SerializableTrait extends Serializable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object SerializableFromScala: SerializableTrait | ||
|
||
object NotSerializableFromScala: NotSerializableTrait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.io.Serializable | ||
|
||
interface TestInterface: Serializable | ||
|
||
object DirectlyImplementsTestInterface: TestInterface | ||
|
||
abstract class ExtendsTestInterface: TestInterface | ||
|
||
object IndirectlyImplementsTestInterface: ExtendsTestInterface() | ||
|
||
object NotSerializable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertSame | ||
import org.junit.Test | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import java.io.ObjectInputStream | ||
import java.io.ObjectOutputStream | ||
import java.io.Serializable | ||
import java.io.* | ||
|
||
class ObjectSerializationIntegrationTest { | ||
@Test | ||
fun `object instance is the same after deserialization`() { | ||
assertEquals(TestObject, serializeDeserialize(TestObject)) | ||
assertSame(TestObject, serializeDeserialize(TestObject)) | ||
assertSame(DirectlyImplementsTestInterface, serializeDeserialize(DirectlyImplementsTestInterface)) | ||
assertSame(IndirectlyImplementsTestInterface, serializeDeserialize(IndirectlyImplementsTestInterface)) | ||
assertSame(SerializableFromScala, serializeDeserialize(SerializableFromScala)) | ||
} | ||
|
||
private fun serializeDeserialize(instance: Serializable): Serializable { | ||
@Test(expected = NotSerializableException::class) | ||
fun `cannot serialize non-serializable object`() { | ||
serializeDeserialize(NotSerializable) | ||
} | ||
|
||
@Test(expected = NotSerializableException::class) | ||
fun `cannot serialize non-serializable object from scala`() { | ||
serializeDeserialize(NotSerializableFromScala) | ||
} | ||
|
||
private fun serializeDeserialize(instance: Any): Any? { | ||
val outputStream = ByteArrayOutputStream() | ||
ObjectOutputStream(outputStream).use { | ||
it.writeObject(instance) | ||
} | ||
return ObjectInputStream(ByteArrayInputStream(outputStream.toByteArray())).use { | ||
it.readObject() as TestObject | ||
it.readObject() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters