Import von generischen Klassen #207

Closed
opened 2019-12-23 16:38:30 +00:00 by pl · 3 comments
Owner

commit c1c12fa33c (HEAD -> addPackages, origin/addPackages)

Beim Test mathStrucVectorTest.java erhält man folgenden Bug:

java.lang.ClassCastException: de.dhbwstuttgart.syntaxtree.type.GenericRefType cannot be cast to de.dhbwstuttgart.syntaxtree.type.RefType
at de.dhbwstuttgart.syntaxtree.factory.ASTFactory.createGeneric(ASTFactory.java:196)
at de.dhbwstuttgart.syntaxtree.factory.ASTFactory.createGenerics(ASTFactory.java:135)
at de.dhbwstuttgart.syntaxtree.factory.ASTFactory.createClass(ASTFactory.java:65)
at de.dhbwstuttgart.core.JavaTXCompiler.getAvailableClasses(JavaTXCompiler.java:138)
at de.dhbwstuttgart.core.JavaTXCompiler.typeInference(JavaTXCompiler.java:463)
at packages.mathStrucVectorTest.testSetPackageNameInBytecodeAndOutputFolder(mathStrucVectorTest.java:42)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:40)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:430)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:71)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

commit c1c12fa33c63c96b798befcf25fd561897c2e359 (HEAD -> addPackages, origin/addPackages) Beim Test mathStrucVectorTest.java erhält man folgenden Bug: java.lang.ClassCastException: de.dhbwstuttgart.syntaxtree.type.GenericRefType cannot be cast to de.dhbwstuttgart.syntaxtree.type.RefType at de.dhbwstuttgart.syntaxtree.factory.ASTFactory.createGeneric(ASTFactory.java:196) at de.dhbwstuttgart.syntaxtree.factory.ASTFactory.createGenerics(ASTFactory.java:135) at de.dhbwstuttgart.syntaxtree.factory.ASTFactory.createClass(ASTFactory.java:65) at de.dhbwstuttgart.core.JavaTXCompiler.getAvailableClasses(JavaTXCompiler.java:138) at de.dhbwstuttgart.core.JavaTXCompiler.typeInference(JavaTXCompiler.java:463) at packages.mathStrucVectorTest.testSetPackageNameInBytecodeAndOutputFolder(mathStrucVectorTest.java:42) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at junit.framework.TestCase.runTest(TestCase.java:176) at junit.framework.TestCase.runBare(TestCase.java:141) at junit.framework.TestResult$1.protect(TestResult.java:122) at junit.framework.TestResult.runProtected(TestResult.java:142) at junit.framework.TestResult.run(TestResult.java:125) at junit.framework.TestCase.run(TestCase.java:129) at junit.framework.TestSuite.runTest(TestSuite.java:252) at junit.framework.TestSuite.run(TestSuite.java:247) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:40) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:430) at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80) at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:71) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137) at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Owner

Fixed mit commit: f59a7d221e

auf branch addPackages

Fixed mit commit: f59a7d221e550236b34393bff1390cd72149bf0c auf branch addPackages
Author
Owner

Es compiliert korrekt. Allerdimngs der Aufruf (aus dem normalen Java) klappt noch nicht.

Mit der Datei mathStrucVectorUse.java:

package de.test;
import de.test.mathStrucVector;

class mathStrucVectorUse {

public static void main(String[] args) {
new mathStrucVector().main();
}

}

erhalte ich die Fehlermeldung

java -cp output de.test.mathStrucVectorUse
Exception in thread "main" java.lang.NoClassDefFoundError: vectorAdd
at de.test.vectorAdd.(vectorAdd.jav)
at de.test.mathStrucVector.main(mathStrucVector.jav)
at de.test.mathStrucVectorUse.main(mathStrucVectorUse.java:8)
Caused by: java.lang.ClassNotFoundException: vectorAdd
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)
... 3 more

Es compiliert korrekt. Allerdimngs der Aufruf (aus dem normalen Java) klappt noch nicht. Mit der Datei mathStrucVectorUse.java: package de.test; import de.test.mathStrucVector; class mathStrucVectorUse { public static void main(String[] args) { new mathStrucVector().main(); } } erhalte ich die Fehlermeldung > java -cp output de.test.mathStrucVectorUse Exception in thread "main" java.lang.NoClassDefFoundError: vectorAdd at de.test.vectorAdd.<init>(vectorAdd.jav) at de.test.mathStrucVector.main(mathStrucVector.jav) at de.test.mathStrucVectorUse.main(mathStrucVectorUse.java:8) Caused by: java.lang.ClassNotFoundException: vectorAdd 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) ... 3 more
Owner

Bist du sicher, dass das ein Problem mit den Packages ist?

Ändert man die Klasse vectorAdd zu der leeren Klasse

package de.test;

class vectorAdd {

}

also löscht das add-Feld und ändert die Datei mathStrucVector.jav zu:

package de.test;

import java.util.Vector;
import java.lang.Integer;
import java.lang.Boolean;

import de.test.vectorAdd;

class mathStrucVector {

main() {
	Vector<Integer> v1 = new Vector<Integer>();
	v1.addElement(2);
	v1.addElement(2);
	Vector<Integer> v2 = new Vector<Integer>();
	v2.addElement(3);
	v2.addElement(3);

	vectorAdd va = new vectorAdd();
}

}

Dann lässt sich der Test problemlos ausführen. Ich glaube nicht, dass es ein Problem bei der Namensauflösung gibt. Java sagt zwar NoClassDefFoundError aber ich denke, das liegt daran, dass am bytecode der Klasse etwas nicht stimmt und das Problem daher in der Bytecodegenerierung liegt.

Bist du sicher, dass das ein Problem mit den Packages ist? Ändert man die Klasse vectorAdd zu der leeren Klasse package de.test; class vectorAdd { } also löscht das add-Feld und ändert die Datei mathStrucVector.jav zu: package de.test; import java.util.Vector; import java.lang.Integer; import java.lang.Boolean; import de.test.vectorAdd; class mathStrucVector { main() { Vector<Integer> v1 = new Vector<Integer>(); v1.addElement(2); v1.addElement(2); Vector<Integer> v2 = new Vector<Integer>(); v2.addElement(3); v2.addElement(3); vectorAdd va = new vectorAdd(); } } Dann lässt sich der Test problemlos ausführen. Ich glaube nicht, dass es ein Problem bei der Namensauflösung gibt. Java sagt zwar NoClassDefFoundError aber ich denke, das liegt daran, dass am bytecode der Klasse etwas nicht stimmt und das Problem daher in der Bytecodegenerierung liegt.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: JavaTX/JavaCompilerCore#207
No description provided.