Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Java 16 language features #40

Open
altrisi opened this issue May 21, 2021 · 5 comments
Open

Support Java 16 language features #40

altrisi opened this issue May 21, 2021 · 5 comments

Comments

@altrisi
Copy link

altrisi commented May 21, 2021

The issue occurred when trying to migrateMappings in a Fabric project (running Loom 0.8, 1.16.5 mod). May be an issue with some Java 16 feature, that class uses at least var. Assumed it's a Mercury issue since it's present in many positions in the stacktrace.

Stacktrace
java.lang.RuntimeException: Failed to process: path\to\altrisi\scarpetapptester\config\GSONRecordAdapter.java
        at org.cadixdev.mercury.Mercury.accept(Mercury.java:237)
        at org.cadixdev.mercury.Mercury$Requestor.acceptAST(Mercury.java:260)
        at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1068)
        at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:662)
        at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:1013)
        at org.cadixdev.mercury.Mercury.run(Mercury.java:212)
        at org.cadixdev.mercury.Mercury.rewrite(Mercury.java:167)
        at net.fabricmc.loom.task.MigrateMappingsTask.migrateMappings(MigrateMappingsTask.java:189)
        at net.fabricmc.loom.task.MigrateMappingsTask.doTask(MigrateMappingsTask.java:104)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.run(ExecuteActionsTaskExecuter.java:498)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:56)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$run$1(DefaultBuildOperationExecutor.java:71)
        at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.runWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:45)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:71)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:483)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:466)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:105)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:270)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:248)
        at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:83)
        at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:37)
        at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:50)
        at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:47)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
        at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
        at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:47)
        at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:37)
        at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:68)
        at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:38)
        at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:50)
        at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:36)
        at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41)
        at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74)
        at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55)
        at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
        at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:29)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:54)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:35)
        at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:60)
        at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:27)
        at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:174)
        at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:74)
        at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:45)
        at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:40)
        at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:29)
        at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:36)
        at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:22)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:99)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:92)
        at java.base/java.util.Optional.map(Optional.java:260)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:52)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36)
        at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:84)
        at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:41)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27)
        at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:91)
        at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:49)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:78)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:49)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:105)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:50)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:86)
        at java.base/java.util.Optional.orElseGet(Optional.java:364)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:86)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:32)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
        at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:43)
        at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:31)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:40)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution$2.withWorkspace(ExecuteActionsTaskExecuter.java:283)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:40)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
        at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
        at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
        at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:49)
        at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:35)
        at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:76)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:184)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:173)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
        at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:74)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:408)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:395)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:388)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:374)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
        at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.IllegalArgumentException: Invalid identifier : >[Ljava<
        at org.eclipse.jdt.core.dom.SimpleName.setIdentifier(SimpleName.java:243)
        at org.eclipse.jdt.core.dom.AST.newSimpleName(AST.java:2597)
        at org.eclipse.jdt.core.dom.AST.newName(AST.java:2285)
        at org.cadixdev.mercury.remapper.RemapperVisitor.remapType(RemapperVisitor.java:124)
        at org.cadixdev.mercury.remapper.RemapperVisitor.visit(RemapperVisitor.java:178)
        at org.cadixdev.mercury.remapper.SimpleRemapperVisitor.visit(SimpleRemapperVisitor.java:183)
        at org.eclipse.jdt.core.dom.SimpleName.accept0(SimpleName.java:198)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.SimpleType.accept0(SimpleType.java:195)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.VariableDeclarationStatement.accept0(VariableDeclarationStatement.java:253)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
        at org.eclipse.jdt.core.dom.Block.accept0(Block.java:128)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.IfStatement.accept0(IfStatement.java:183)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
        at org.eclipse.jdt.core.dom.Block.accept0(Block.java:128)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:617)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
        at org.eclipse.jdt.core.dom.AnonymousClassDeclaration.accept0(AnonymousClassDeclaration.java:135)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.ClassInstanceCreation.accept0(ClassInstanceCreation.java:305)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.ReturnStatement.accept0(ReturnStatement.java:128)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
        at org.eclipse.jdt.core.dom.Block.accept0(Block.java:128)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2975)
        at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:617)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
        at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:447)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2998)
        at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:258)
        at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2927)
        at org.cadixdev.mercury.remapper.MercuryRemapper.rewrite(MercuryRemapper.java:54)
        at org.cadixdev.mercury.SourceRewriter.process(SourceRewriter.java:20)
        at org.cadixdev.mercury.SourceContext.process(SourceContext.java:82)
        at org.cadixdev.mercury.RewriteContext.process(RewriteContext.java:106)
        at org.cadixdev.mercury.Mercury.accept(Mercury.java:235)
        ... 136 more
:remapped project written to path\to\remappedSrc
Class where it fails
package altrisi.scarpetapptester.config;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.HashMap;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

class GSONRecordAdapter implements TypeAdapterFactory {
	
    @Override
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
       @SuppressWarnings("unchecked")
       Class<T> clazz = (Class<T>) type.getRawType();
       if (!clazz.isRecord()) {
          return null;
       }
       TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);

       return new TypeAdapter<T>() {
          @Override
          public void write(JsonWriter out, T value) throws IOException {
             delegate.write(out, value);
          }

          @Override
          public T read(JsonReader reader) throws IOException {
             if (reader.peek() == JsonToken.NULL) {
                reader.nextNull();
                return null;
             } else {
                var recordComponents = clazz.getRecordComponents();
                var typeMap = new HashMap<String,TypeToken<?>>();
                for (int i = 0; i < recordComponents.length; i++) {
                   typeMap.put(recordComponents[i].getName(), TypeToken.get(recordComponents[i].getGenericType()));
                }
                var argsMap = new HashMap<String,Object>();
                reader.beginObject();
                while (reader.hasNext()) {
                   String name = reader.nextName();
                   argsMap.put(name, gson.getAdapter(typeMap.get(name)).read(reader));
                }
                reader.endObject();

                var argTypes = new Class<?>[recordComponents.length];
                var args = new Object[recordComponents.length];
                for (int i = 0; i < recordComponents.length; i++) {
                   argTypes[i] = recordComponents[i].getType();
                   args[i] = argsMap.get(recordComponents[i].getName());
                }
                Constructor<T> constructor;
                try {
                   constructor = clazz.getDeclaredConstructor(argTypes);
                   constructor.setAccessible(true);
                   return constructor.newInstance(args);
                } catch (IllegalArgumentException | ReflectiveOperationException e) {
                   throw new RuntimeException(e);
                }
             }
          }
       };
    }
}

Also (not sure if this is an issue with Mercury or not), after removing that class and running migrateMappings again, classes which declared records as nested classes got a failing import record; in their list of imports, and var was replaced with the actual type.

@jamierocks
Copy link
Member

It's probably a consequence of the JDT being old in the published build - will update and publish a new Mercury version soon.

@jamierocks
Copy link
Member

0277125 may well present a fix, unsure though.

@jamierocks jamierocks changed the title java.lang.RuntimeException: Failed to process: ... Support Java 16 language features Jun 1, 2021
@jpenilla
Copy link

Tested with Mercury 0.1.0 and manually bumping JDT to 3.27.0, records still don't remap properly/at all. References to records get remapped properly, however records themselves are not remapped. Top level records have the .java file renamed and nothing else, inner records fail to remap and seem to cause Mercury to give up on remapping that java file.

@quat1024
Copy link

quat1024 commented Dec 3, 2021

Ran into this when using Loom's migrateMappings task to convert a 1.17 mod that used records in its source code from yarn to mojang names. No members inside the record get remapped; sometimes it would just delete all the imports from the file and carry on.

Since I control the mod source, the solution was to use intellij's "convert record to class" intention on all the records, run the Gradle task, then convert them all back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants