Fabric instance crashing when creating custom item group - java

I tried making a custom item group for my mod but when I run the code, the game instantly crashes.
fabric 1.19.2
package com.end3r.cripplingteas.item;
import com.end3r.cripplingteas.CripplingTeasMod;
import com.end3r.cripplingteas.Registry.ModItems;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
public class ModItemGroup {
public static final ItemGroup CRIPPLINGTEAS = FabricItemGroupBuilder.build(
new Identifier(CripplingTeasMod.teas, "Crippling Teas"), () -> new ItemStack(ModItems.BASIC_TEA))
;
}
i tried writing a custom item group for my mod using FabricItemGroupBuilder
logs:
Description: Initializing game
java.lang.RuntimeException: Could not execute entrypoint stage 'main' due to errors, provided by 'teas'!
at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.lambda$invoke0$0(EntrypointUtils.java:51)
at net.fabricmc.loader.impl.util.ExceptionUtil.gatherExceptions(ExceptionUtil.java:33)
at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.invoke0(EntrypointUtils.java:49)
at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.invoke(EntrypointUtils.java:35)
at net.fabricmc.loader.impl.game.minecraft.Hooks.startClient(Hooks.java:52)
at net.minecraft.client.MinecraftClient.<init>(MinecraftClient.java:523)
at net.minecraft.client.main.Main.main(Main.java:184)
at net.minecraft.client.main.Main.main(Main.java:56)
at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:461)
at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)
at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23)
at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)
Caused by: java.lang.ExceptionInInitializerError
at com.end3r.cripplingteas.Registry.ModItems.<clinit>(ModItems.java:21)
at com.end3r.cripplingteas.CripplingTeasMod.onInitialize(CripplingTeasMod.java:12)
at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.invoke0(EntrypointUtils.java:47)
... 9 more
Caused by: net.minecraft.util.InvalidIdentifierException: Non [a-z0-9/._-] character in path of location: teas:Crippling Teas
at net.minecraft.util.Identifier.<init>(Identifier.java:140)
at net.minecraft.util.Identifier.<init>(Identifier.java:144)
at com.end3r.cripplingteas.item.ModItemGroup.<clinit>(ModItemGroup.java:11)
... 12 more

You should follow the identifier rules. Crippling Teas isn't valid as:
contains a space
with upper cases
Actually, identifier should only be like crippling_teas.

Related

Get SubTypes in Java with Reflections library

I try to get classes that implements an interface in a given package, using reflections library.
I have the following code :
package TestClass;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import java.io.DataInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
public class Checks {
public static void main(String[] args) {
Reflections reflections = new Reflections("TestReflection.src.testclass");
try{
Set<Class<? extends CheckingClass>> classes = reflections.getSubTypesOf(CheckingClass.class);
}catch(Exception e){
System.out.println(e.toString());
}
}
}
It gives me this error : org.reflections.ReflectionsException: Scanner SubTypesScanner was not configured
It surprises me because i got the code from an example of how to use reflections library, so it should work.
The library, i think, is well imported because other methods work.
I've tried a lot of things and can't make this code work.
Maybe i'm missing an important details. Any idea?
Thanks
EDIT : Here's the tree of my project, so you can see if my path is good :
EDIT 2 : I changed
Reflections reflections = new Reflections("TestReflection.src.testclass", new SubTypesScanner());
to
Reflections reflections = new Reflections("testclass", new SubTypesScanner());
and i have an other error :
Exception in thread "main" java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at org.reflections.adapters.JavassistAdapter.getOrCreateClassObject(JavassistAdapter.java:107)
at org.reflections.adapters.JavassistAdapter.getOrCreateClassObject(JavassistAdapter.java:34)
at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:28)
at org.reflections.Reflections.scan(Reflections.java:270)
at org.reflections.Reflections.scan(Reflections.java:216)
at org.reflections.Reflections.<init>(Reflections.java:137)
at org.reflections.Reflections.<init>(Reflections.java:182)
at org.reflections.Reflections.<init>(Reflections.java:155)
at testclass.Checks.main(Checks.java:12)
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 9 more
Process finished with exit code 1

Dataflow job template creation errors out

I want to create a dataflow job template that takes the filename in GCS and publishes it to a PubSub topic. I followed the tutorial at this link, but that doesn't seem to be working for me.
My class definition is the following -
import com.google.cloud.dataflow.sdk.Pipeline;
import com.google.cloud.dataflow.sdk.io.PubsubIO;
import com.google.cloud.dataflow.sdk.io.TextIO;
import com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory;
import com.google.cloud.dataflow.sdk.runners.TemplatingDataflowPipelineRunner;
public class PubSubOutputTest {
public static void main(String[] args) {
// Create pipeline options.
pubSubOutputOptions options = PipelineOptionsFactory.fromArgs(args).as(pubSubOutputOptions.class);
options.setRunner(TemplatingDataflowPipelineRunner.class);
options.setTempLocation("gs://staging-bucket");
Pipeline p = Pipeline.create(options);
// Read the file from the GCS Bucket.
p.apply(TextIO.Read.named("Read file from GCS.").from(options.getInputFile()).withoutValidation())
.apply(PubsubIO.Write.named("Write to Pub Sub topic.")
.topic("projects/my-project/topics/my-topic"));
// Run the pipeline.
p.run();
}
}
The interface that implements the ValueProvider to grab the runtime inputs is the following -
import com.google.cloud.dataflow.sdk.options.Default;
import com.google.cloud.dataflow.sdk.options.PipelineOptions;
import com.google.cloud.dataflow.sdk.options.ValueProvider;
public interface pubSubOutputOptions extends PipelineOptions {
#Default.String("gs://default-file.txt")
ValueProvider getInputFile();
void setInputFile(ValueProvider value);
}
The template creation is giving the following error.
Exception in thread "main" java.lang.IllegalArgumentException: PipelineOptions specified failed to serialize to JSON.
at com.google.cloud.dataflow.sdk.runners.DataflowPipelineTranslator$Translator.translate(DataflowPipelineTranslator.java:408)
at com.google.cloud.dataflow.sdk.runners.DataflowPipelineTranslator.translate(DataflowPipelineTranslator.java:146)
at com.google.cloud.dataflow.sdk.runners.DataflowPipelineRunner.run(DataflowPipelineRunner.java:570)
at com.google.cloud.dataflow.sdk.runners.TemplatingDataflowPipelineRunner.run(TemplatingDataflowPipelineRunner.java:137)
at com.google.cloud.dataflow.sdk.runners.TemplatingDataflowPipelineRunner.run(TemplatingDataflowPipelineRunner.java:44)
at com.google.cloud.dataflow.sdk.Pipeline.run(Pipeline.java:181)
at com.my.project.dataflow.PubSubOutputTest.main(PubSubOutputTest.java:32)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Unexpected IOException (of type java.io.IOException): Failed to serialize and deserialize property 'inputFile' with value 'RuntimeValueProvider{propertyName=inputFile, default=gs://default-file.txt, value=null}'
at com.fasterxml.jackson.databind.JsonMappingException.fromUnexpectedIOE(JsonMappingException.java:284)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:3008)
at com.google.cloud.dataflow.sdk.runners.DataflowPipelineTranslator$Translator.translate(DataflowPipelineTranslator.java:406)
I am new to Google Cloud Dataflow and Java. I implemented everything in the documentation but I could have missed something obvious.
It looks like there's an error with how you're declaring the option. I think you want to provide a template parameter to ValueProvider, like so:
#Default.String("gs://default-file.txt")
ValueProvider<String> getInputFile();
void setInputFile(ValueProvider<String> value);

WritableStringObjectInspector cannot be cast to BooleanObjectInspector

Every time i run a hive query which has an OR condition from my java program, I get the following error,
Caused by: java.lang.ClassCastException: org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector cannot be cast to org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector
at org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPOr.initialize(GenericUDFOPOr.java:53)
at org.apache.hadoop.hive.ql.udf.generic.GenericUDF.initializeAndFoldConstants(GenericUDF.java:117)
at org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc.newInstance(ExprNodeGenericFuncDesc.java:232)
at org.apache.hadoop.hive.ql.parse.TypeCheckProcFactory$DefaultExprProcessor.getXpathOrFuncExprNodeDesc(TypeCheckProcFactory.java:958)
at org.apache.hadoop.hive.ql.parse.TypeCheckProcFactory$DefaultExprProcessor.process(TypeCheckProcFactory.java:1175)
at org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher.dispatch(DefaultRuleDispatcher.java:90)
at org.apache.hadoop.hive.ql.lib.DefaultGraphWalker.dispatchAndReturn(DefaultGraphWalker.java:94)
at org.apache.hadoop.hive.ql.lib.DefaultGraphWalker.dispatch(DefaultGraphWalker.java:78)
at org.apache.hadoop.hive.ql.lib.DefaultGraphWalker.walk(DefaultGraphWalker.java:132)
at org.apache.hadoop.hive.ql.lib.DefaultGraphWalker.startWalking(DefaultGraphWalker.java:109)
at org.apache.hadoop.hive.ql.parse.TypeCheckProcFactory.genExprNode(TypeCheckProcFactory.java:192)
at org.apache.hadoop.hive.ql.parse.TypeCheckProcFactory.genExprNode(TypeCheckProcFactory.java:145)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genAllExprNodeDesc(SemanticAnalyzer.java:10650)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genExprNodeDesc(SemanticAnalyzer.java:10606)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genExprNodeDesc(SemanticAnalyzer.java:10577)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genFilterPlan(SemanticAnalyzer.java:2736)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genFilterPlan(SemanticAnalyzer.java:2717)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genBodyPlan(SemanticAnalyzer.java:8972)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genPlan(SemanticAnalyzer.java:9884)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genPlan(SemanticAnalyzer.java:9777)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genOPTree(SemanticAnalyzer.java:10250)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10261)
at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10141)
at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:222)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:430)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:305)
at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1123)
at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1110)
at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:99)
... 26 more
But when i tried to run the following java program just to test the casting, it is cast successfully.
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector;
public class MyClass {
public static void main(String[] args) {
ObjectInspector[] arguments = new ObjectInspector[2];
BooleanObjectInspector boi0 = (BooleanObjectInspector) arguments[0];
BooleanObjectInspector boi1 = (BooleanObjectInspector) arguments[1];
System.out.println(boi1);
}
}
I have only one jar file which is hive-exec-5.5.4 in my classpath. So i dont see any jar conflicts. Any other solutions?
My Bad,
The Right end of the OR clause in the query did not have a condition after key. I have solved the issue.

How do I use an inner (nested) class created with a groovy AST transformation?

I am trying to use groovy to write an annotation and ASTTransformation which will create an inner class.
Here is the annotation:
import org.codehaus.groovy.transform.GroovyASTTransformationClass;
import java.lang.annotation.*;
#Retention(RetentionPolicy.SOURCE)
#Target(ElementType.TYPE)
#GroovyASTTransformationClass("WithInnerClassTransformation")
public #interface WithInnerClass {
public String name();
}
And the transformation:
import org.codehaus.groovy.ast.*;
import org.codehaus.groovy.control.*;
import org.codehaus.groovy.transform.*;
#GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
public class WithInnerClassTransformation implements ASTTransformation {
public void visit(ASTNode[] nodes, SourceUnit source) {
ClassNode outer = nodes[1];
String name = nodes[0].getMember('name').text;
def innerClassNode = new InnerClassNode(
outer,
"$outer.name\$$name",
ClassNode.ACC_PUBLIC,
new ClassNode(GroovyObject),
);
def compilerConfiguration = source.getAST().getUnit().config;
def compilationUnit = new CompilationUnit(compilerConfiguration);
compilationUnit.addClassNode(innerClassNode);
compilationUnit.compile();
}
}
A simple usage of the above:
#WithInnerClass(name = "InnerClass")
public class OuterClass {}
Using the following script, I confirmed that the generated class is accessible through the system class loader.
def classLoader = ClassLoader.getSystemClassLoader()
Class inner = classLoader.loadClass("OuterClass\$InnerClass")
assert inner.simpleName == "InnerClass"
assert OuterClass.declaredClasses.toList().contains(inner)
println OuterClass.InnerClass.class
However, when I attempt to explicitly make use of the class, I receive this error message:
Exception in thread "main" groovy.lang.MissingPropertyException: No such property: InnerClass for class: OuterClass
at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:997)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1852)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1828)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735)
at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:291)
at main.run(main.groovy:5)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1208)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1017)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:914)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:897)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:407)
at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at main.main(main.groovy)
Additionally, attempting to use an import results in this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
main.groovy: 1: unable to resolve class OuterClass.InnerClass
# line 1, column 1.
import OuterClass.InnerClass
^
It appears that in order to explicitly use a generated class, a couple extra rounds of compilation are required. To make this code run correctly (and even be able to import the generated class), compile in 3 steps.
groovyc WithInnerClass.groovy WithInnerClassTransformation.groovy
groovyc OuterClass.groovy
groovyc main.groovy
WithInnerClass.groovy and WithInnerClassTransformation.groovy must be compiled separately from OuterClass.groovy in order for an OuterClass$InnerClass.class file to be generated.
Additionally, OuterClass.groovy must be compiled separately from main.groovy. While OuterClass$InnerClass.class will appear in the classpath in this case, for reasons I'm not clear on, this is insufficient to be able to explicitly use InnerClass inside of main.groovy. Compiling main.groovy separately, groovyc is able to pull in the "real" class file.

Simple Apache-commons configuration example throws ConfigurationRuntimeException

I'm trying to test a very simple example given in the Apache-commons configuration library user's guide regarding declaring and creating beans. I copied the code in the example almost word by word, and yet I'm getting a ConfigurationRuntimeException (this after overcoming a different exception, see this question).
Here is the xml file I'm using - windowcongif.xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<config>
<gui>
<windowManager config-class="test.DefaultWindowManager"
closable="false" resizable="true" defaultWidth="400"
defaultHeight="250">
</windowManager>
</gui>
</config>
Here is the code in the file WindowManager.java:
package test;
public interface WindowManager {}
Here is the code in the file DefaultWindowManager.java:
package test;
public class DefaultWindowManager implements WindowManager {
private boolean resizable;
private boolean closable;
private int defaultWidth;
private int defaultHeight;
}
Here is the code in the file Main.java:
package test;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.beanutils.BeanDeclaration;
import org.apache.commons.configuration.beanutils.BeanHelper;
import org.apache.commons.configuration.beanutils.XMLBeanDeclaration;
import org.apache.commons.beanutils.PropertyUtils;
public class Main {
public static void main(String[] args) throws ConfigurationException {
XMLConfiguration config = new XMLConfiguration("windowconfig.xml");
BeanDeclaration decl = new XMLBeanDeclaration(config, "gui.windowManager");
WindowManager wm = (WindowManager) BeanHelper.createBean(decl);
}
}
Here is the output during runtime:
Exception in thread "main" org.apache.commons.configuration.ConfigurationRuntimeException: org.apache.commons.configuration.ConfigurationRuntimeException: Property defaultHeight cannot be set on test.DefaultWindowManager
at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:341)
at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:358)
at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:372)
at test.Main.main(Main.java:24)
Caused by: org.apache.commons.configuration.ConfigurationRuntimeException: Property defaultHeight cannot be set on test.DefaultWindowManager
at org.apache.commons.configuration.beanutils.BeanHelper.initProperty(BeanHelper.java:271)
at org.apache.commons.configuration.beanutils.BeanHelper.initBeanProperties(BeanHelper.java:229)
at org.apache.commons.configuration.beanutils.BeanHelper.initBean(BeanHelper.java:166)
at org.apache.commons.configuration.beanutils.DefaultBeanFactory.initBeanInstance(DefaultBeanFactory.java:108)
at org.apache.commons.configuration.beanutils.DefaultBeanFactory.createBean(DefaultBeanFactory.java:64)
at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:336)
... 3 more
How do I make this simple example work?
I'm using version 1.9 of the commons-configuration package and version 1.8.3 of the commons-beanutils package, auto-imported by IntelliJ IDEA after putting the dependencies in the pom.xml file, and version 1.7.0_17 of java running on Windows 8 64bit.
If you are using JavaBeans you will need to add a setter for each field you want to set.
I suggest using the add setter and getter in IntelliJ for these fields.
The example states
// getters and setters ommitted, also the WindowManager methods

Categories