Obsidian icon indicating copy to clipboard operation
Obsidian copied to clipboard

obsidianc crashes if the input file begins with a dot, or is not a valid Java class name in som way

Open ishantheperson opened this issue 4 years ago • 0 comments

Describe the bug Currently the source file name is used when generated some of the class names, this causes crashes if it isn't a valid class name in Java.

To Reproduce

ishan@ishan-macbook ~ > cat .testing.obs
main contract Foo { }
ishan@ishan-macbook ~ > obsidianc .testing.obs
org/hyperledger/fabric/example/Contract.java
org/hyperledger/fabric/example/Foo.java
Exception in thread "main" java.lang.IllegalArgumentException: Part '' of the package name 'org.hyperledger.fabric.example..testingOuterClass' is invalid
	at com.helger.jcodemodel.JPackage.<init>(JPackage.java:194)
	at com.helger.jcodemodel.JCodeModel.lambda$_package$0(JCodeModel.java:226)
	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
	at com.helger.jcodemodel.JCodeModel._package(JCodeModel.java:226)
	at com.helger.jcodemodel.JDirectClass._package(JDirectClass.java:122)
	at com.helger.jcodemodel.writer.JFormatter$NameUsage.isAmbiguousIn(JFormatter.java:127)
	at com.helger.jcodemodel.writer.JFormatter.writeClassFull(JFormatter.java:925)
	at com.helger.jcodemodel.writer.JCMWriter.buildPackage(JCMWriter.java:324)
	at com.helger.jcodemodel.writer.JCMWriter.build(JCMWriter.java:288)
	at com.helger.jcodemodel.writer.JCMWriter.build(JCMWriter.java:226)
	at com.helger.jcodemodel.writer.JCMWriter.build(JCMWriter.java:198)
	at com.helger.jcodemodel.writer.JCMWriter.build(JCMWriter.java:239)
	at edu.cmu.cs.obsidian.Main$.compileProgram(Main.scala:348)
	at edu.cmu.cs.obsidian.Main$.compileProgram(Main.scala:247)
	at edu.cmu.cs.obsidian.Main$.main(Main.scala:239)
	at edu.cmu.cs.obsidian.Main.main(Main.scala)

ishantheperson avatar Apr 21 '20 20:04 ishantheperson