mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: fix crash in WeakReference constructor
It occurred when ReferenceQueue.remove method was never used Fix #756
This commit is contained in:
parent
e02f91b0fd
commit
fa2e003dd6
|
@ -47,6 +47,12 @@ public class ReferenceQueueGenerator implements Generator {
|
|||
writer.append(context.getParameterName(0)).append(".").appendField(INNER_FIELD).ws().append("=")
|
||||
.ws().append("[];").softNewLine();
|
||||
|
||||
if (context.getDependency().getMethod(REPORT_METHOD) != null) {
|
||||
generateFinalizationRegistry(context, writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateFinalizationRegistry(GeneratorContext context, SourceWriter writer) throws IOException {
|
||||
writer.append(context.getParameterName(0)).append(".").appendField(REGISTRY_FIELD).ws().append("=")
|
||||
.ws().append("new $rt_globals.FinalizationRegistry(ref").ws().append("=>").appendBlockStart();
|
||||
writer.appendIf().append("!").appendMethodBody(REPORT_METHOD).append("(")
|
||||
|
|
|
@ -55,10 +55,15 @@ public class WeakReferenceGenerator implements Generator {
|
|||
writer.appendIf().append(context.getParameterName(2)).ws().append("!==").ws().append("null")
|
||||
.ws().append("&&").ws().append("supported)")
|
||||
.appendBlockStart();
|
||||
writer.append(context.getParameterName(2)).append(".")
|
||||
.appendField(new FieldReference(ReferenceQueue.class.getName(), "registry"))
|
||||
.append(".").append("register(").append(context.getParameterName(1))
|
||||
|
||||
writer.append("var registry").ws().append("=").ws()
|
||||
.append(context.getParameterName(2)).append(".")
|
||||
.appendField(new FieldReference(ReferenceQueue.class.getName(), "registry")).append(";")
|
||||
.softNewLine();
|
||||
writer.appendIf().append("registry").ws().append("!==").ws().append("null)").ws();
|
||||
writer.append("registry.register(").append(context.getParameterName(1))
|
||||
.append(",").ws().append(context.getParameterName(0)).append(");").softNewLine();
|
||||
|
||||
writer.appendBlockEnd();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,8 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.teavm.junit.SkipJVM;
|
||||
import org.teavm.junit.TeaVMTestRunner;
|
||||
import org.teavm.junit.WholeClassCompilation;
|
||||
|
||||
@RunWith(TeaVMTestRunner.class)
|
||||
@WholeClassCompilation
|
||||
@SkipJVM
|
||||
public class WeakReferenceTest {
|
||||
private Node lastNode;
|
||||
|
|
Loading…
Reference in New Issue
Block a user