Echtzeitsysteme / java-refactoring-ttc

Object-oriented Refactoring of Java Programs using Graph Transformation (TTC'2015)
0 stars 0 forks source link

pub_csc1_2: Error: Could not find or load main class example04.ChildClass1 #33

Closed tsdh closed 9 years ago

tsdh commented 9 years ago

I get this output:

Executing test case: "pub_csc1_2"
    Description:
        EXS-POS: Create a superclass in a new package.

SUCCESS: The java program has been compiled.

    Output of execution before refactoring:

sssssssssssssss Triggering Program Graph Generation ssssssssssssssss
createProgramGraph(/tmp/tmp_ttc/paper-example04)
Parsing file /tmp/tmp_ttc/paper-example04/src/example04/ChildClass2.java... Done
Parsing file /tmp/tmp_ttc/paper-example04/src/example04/ChildClass1.java... Done
Base-package is example04
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

ssssssssssss  Triggering Extract Superclass Refactoring ssssssssssss
applyCreateSuperClass([example04.ChildClass1, example04.ChildClass2], foo.Foo)
Creating new superclass foo.Foo with no parent
The create-superclass rule did match!
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

ssssssssssss  Triggering Synchronization with Java Code ssssssssssss
Deleting folder /home/horn/tmp/JR/refactoring2-before
Copying /tmp/tmp_ttc/paper-example04 to /home/horn/tmp/JR/refactoring2-before
synchronizeChanges(): 1 changes to be applied
Saving resource to /tmp/tmp_ttc/paper-example04/src/example04/ChildClass2.java
Saving resource to /tmp/tmp_ttc/paper-example04/src/example04/ChildClass1.java
Saving resource to /tmp/tmp_ttc/paper-example04/src/example04/Foo.java
Deleting folder /home/horn/tmp/JR/refactoring2-after
Copying /tmp/tmp_ttc/paper-example04 to /home/horn/tmp/JR/refactoring2-after
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

    Output of execution after refactoring:
Error: Could not find or load main class example04.ChildClass1

FAILURE: The program does not run proper.

--------------------------------------------------------------------
FAILURE: Test case "pub_csc1_2" has not been executed successfully.
The solution needed 0.006 seconds for execution. 
--------------------------------------------------------------------

ChildClass1 after the transformation looks like this:

package example04;
public class ChildClass1 extends Foo {
    public static void main(String[]args) {
    }
    public void method() {
        System.out.println("Hello World!");
    }
}

Before it was

package example04;
public class ChildClass1 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }

    public void method(){
        System.out.println("Hello World!");
    }
}

So why is it not runnable anymore? Nothing has changed except that it is now a Foo subclass and the comment in main() is gone because JaMoPP doesn't save comments.

tsdh commented 9 years ago

The *.class files are there, too, and I can run it with java example04.ChildClass1 just fine.

SvenPeldszus commented 9 years ago

Well that is a good question.

We call:

Runtime runtime = Runtime.getRuntime();
String java = System.getProperty("java.home")+"/bin/java";
String main_class = "example04.ChildClass1"

Process p = runtime.exec("\""+java+"\" -cp "+program_folder+"/src"+" "+main_class);

All path separators are of course retrieved via system properties in the real ARTE code.

At the moment I do not see what has changed in this case.

tsdh commented 9 years ago

java -cp paper-example04/src example04.ChildClass1 works, too.

Hm, the message Error: Could not find or load main class example04.ChildClass1 is already what the process emits on its error stream, right? Maybe some timing problem, e.g., you compile the classes also using a process and don't wait for it to be finished (p.waitFor()) before starting the program?

SvenPeldszus commented 9 years ago

Ok,

we definitely wait for the compilation task to finish.

Yes this message is the error stream of the java process.

Therefore has to be found. The name of the main class seems to be correct, too.

So only the given class path is left as source of the failing execution. As we use the same path for compilation and have an existence check only the src folder is left as a source of the error.

As only this singe program fails I am sure this folder is existent, too.

Do you maybe have created the new java files outside of the src folder?

Have you tried to manually call the executen with the -cp classpath argument or was your current directory always the program location?

$JAVA_HOME/bin/java -cp /tmp/tmp_ttc/paper-example04/src ecample04.ChildClass1

If the JAVA_HOME path variable is not set on your system this is not the problem as ARTE doesn't access it.

tsdh commented 9 years ago

I'll debug a bit more tomorrow. Today I've had no time...

SvenPeldszus commented 9 years ago

No problem, I just wanted to keep you up to date

tsdh commented 9 years ago

Ah, I found the problem! The new class is foo.Foo but my transformation puts it in a file example04/Foo.java. That won't compile of course.

I really wonder why it works for you... But at least ARTE should tell us if the sources don't compile. In the current case, javac emits

paper-example04/src/example04/Foo.java:4: error: duplicate class: foo.Foo
class Foo {
^
paper-example04/src/example04/ChildClass1.java:4: error: cannot access Foo
public class ChildClass1 extends Foo {
                                 ^
  bad source file: paper-example04/src/example04/Foo.java
    file does not contain class example04.Foo
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.

That's a lot more helpful than just java complaining that it cannot find the main class.