Problems with Netbeans 6.9.1

138 views
Skip to first unread message

josemari

unread,
Mar 4, 2011, 8:54:29 AM3/4/11
to cofoja
Hello!

I think your project is great. I'm beginning to do some tests with it
and I'm having some troubles. I'm using Netbeans 6.9.1 and I've added
to the project a compile-time library "ccofoja-1.0-20110213.jar".

In the compiling configuration, I've enabled "Enable Annotation
Processing" with annotation processor
"com.google.java.contract.core.apt.AnnotationProcessor".

In Additional Compiler Options, I have written

"-Acom.google.java.contract.debug".

Finally, in Run configuration, VM Options are:

-javaagent:"./dist/lib/ccofoja-1.0.20110213.jar".

Then, when I execute the program, I can't see any contract violation.
My example project code is short and easy. An interface

package cofoja_test;

import com.google.java.contract.Ensures; import
com.google.java.contract.Requires;

public interface Time {

@Ensures({
"result >= 0", "result <= 23"
}) int getHour();
@Requires({
"h >= 0", "h <= 23"
}) @Ensures("getHour() == h") void setHour(int h);
}


and the next main class:


package cofoja_test;

public class Main implements Time {

int h = 0;

public static void main(String args) {
System.out.println("Ejecutando..."); Main main = new Main();
main.setHour(37);
}

@Override public int getHour() {
return h;
}

@Override public void setHour(int h) {
this.h = h;
}
}


And I think that the method call "main.setHour(37)" should violate the
contract.

Thanks in advance. Greetings.

David Morgan ☯

unread,
Mar 4, 2011, 9:19:24 AM3/4/11
to cof...@googlegroups.com, josemari
Hi Jose,

Glad that you like it!

The annotation processor only sees classes that have one of our
annotations on them. So, since your Main class has no contract
annotations, it will need the special @Contracted annotation at the
class level.

To make this less of a worry there is a check at runtime for the
@Contracted annotation; the fact that it didn't fire suggests that the
javaagent flag is not being passed.

So, some concrete suggestions:
- Check that the contracts are compiled; alongside the output .class
files you should have contract files
- Add the @Contracted annotation and see if that makes a difference
- Try running the output directly using "java -javaagent:<cofoja jar>
Main" on the command line

Hope that helps,

David

David Morgan ☯

unread,
Mar 4, 2011, 9:50:05 AM3/4/11
to cof...@googlegroups.com, josemari
Leonardo just checked locally and it looks like the @Contracted check
may not be working -- in which case adding @Contracted should fix your
problem.

Please try it and let us know :)

Cheers

David

David Smith

unread,
Mar 6, 2011, 3:20:29 PM3/6/11
to cof...@googlegroups.com
Did you check to see if the @Con~ was annotated correctly?


BTW how did i get on this trail?

David Smith

unread,
Mar 6, 2011, 3:20:54 PM3/6/11
to cof...@googlegroups.com
Never mind - Good groups email, ops.

josemari

unread,
Mar 7, 2011, 6:29:24 AM3/7/11
to cofoja
Hello!

I've been playing with it. I wrote only one source file, Main.java,
which contains the interface Time and the class Main. Using NetBeans,
I added the @Contracted annotation to the Main class and the compiler
produced the contract files (Time.contracts, Main.contracts and Time
$com$google$java$contract$H.class). Then, I tried to run the project
with -javaagent:../ccofoja-1.0-20110213.jar and I got the following
error:

Exception in thread "main" java.lang.NoClassDefFoundError: cofoja/Time
$com$google$java$contract$H
at cofoja.Main.com$google$java$contract$P$setHour(Main.java)
at cofoja.Main.setHour(Main.java)
at cofoja.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: cofoja.Time$com$google
$java$contract$H
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 3 more
Java Result: 1

However, I tried the command line and it worked!

prompt>java -javaagent:../../ccofoja-1.0-20110213.jar -jar cofoja.jar

Exception in thread "main" com.google.java.contract.PreconditionError:
h <= 23
at cofoja.Time$com$google$java$contract$H.com$google$java
$contract$PH$co
foja$Time$setHour(Time.java:40)
at cofoja.Main.setHour(Main.java)
at cofoja.Main.main(Main.java:15)



On 6 mar, 21:20, David Smith <packetsp...@gmail.com> wrote:
> Never mind - Good groups email, ops.
>
>
>
>
>
>
>
> On Sun, Mar 6, 2011 at 3:20 PM, David Smith <packetsp...@gmail.com> wrote:
> > Did you check to see if the @Con~ was annotated correctly?
>
> > BTW how did i get on this trail?
>
> > On Fri, Mar 4, 2011 at 9:50 AM, David Morgan ☯ <davidmor...@google.com>wrote:
>
> >> Leonardo just checked locally and it looks like the @Contracted check
> >> may not be working -- in which case adding @Contracted should fix your
> >> problem.
>
> >> Please try it and let us know :)
>
> >> Cheers
>
> >> David
>
> >> On Fri, Mar 4, 2011 at 15:19, David Morgan ☯ <davidmor...@google.com>
> >> wrote:
> >> > Hi Jose,
>
> >> > Glad that you like it!
>
> >> > The annotation processor only sees classes that have one of our
> >> > annotations on them. So, since your Main class has no contract
> >> > annotations, it will need the special @Contracted annotation at the
> >> > class level.
>
> >> > To make this less of a worry there is a check at runtime for the
> >> > @Contracted annotation; the fact that it didn't fire suggests that the
> >> > javaagent flag is not being passed.
>
> >> > So, some concrete suggestions:
> >> >  - Check that the contracts are compiled; alongside the output .class
> >> > files you should have contract files
> >> >  - Add the @Contracted annotation and see if that makes a difference
> >> >  - Try running the output directly using "java -javaagent:<cofoja jar>
> >> > Main" on the command line
>
> >> > Hope that helps,
>
> >> > David
>
> >> > On Fri, Mar 4, 2011 at 14:54, josemari <wyatt.earp.1848.1...@gmail.com>

Nhat Minh Le

unread,
Mar 7, 2011, 6:41:22 AM3/7/11
to cof...@googlegroups.com, wyatt.earp...@gmail.com
What is cofoja.jar? Is that your program? Looks like the class path
differs from the NetBeans run. If you're packaging a JAR file, make
sure that it grabs the helper class files (both the .contracts and the
additional .class files that are produced for interfaces).

Do you see the class cofoja/Time$com$google$java$contract$H somewhere
in your class output directory? If so, does it appear to be in your
classpath?

--
Nhat

josemari

unread,
Mar 7, 2011, 9:16:27 AM3/7/11
to cofoja
Yes, "cofoja.jar" is my program -"cofoja" is the name of the project-,
I'm packaging a jar file. Both the contracts ("Main.contracts" and
"Time.contracts") and the class file for the interface ("Time$com
$google$java$contract$H.class") are within the jar file and in the
"build\classes\cofoja" folder after compiling. And I have detected the
problem. When I run the project from inside Netbeans, I can see at the
windows explorer that the file "Time$com$google$java$contract$H.class"
is renamed to "Main.rs" and this file ("Main.rs") only contains two
lines:

cofoja.Time
cofoja.Main


The file "Time$com$google$java$contract$H.class" disappeared. It's in
the jar but not in the "build\classes\cofoja" folder after running the
project. Maybe netbeans is doing something wrong.

On 7 mar, 12:41, Nhat Minh Le <nhat.minh...@huoc.org> wrote:

josemari

unread,
Mar 8, 2011, 4:47:33 AM3/8/11
to cofoja
I've just checked something. I have run the project inside Netbeans
the first time and the file "Main.rs" appeared. Then I've copied "Time
$com
$google$java$contract$H.class" -which I previously saved in a
temporal directory after compiling the project- in the "build\classes
\cofoja" folder and now, with both files in that folder, I've run the
project again and now it works from inside the IDE.

David Morgan ☯

unread,
Mar 8, 2011, 4:50:57 AM3/8/11
to cof...@googlegroups.com, josemari
Interesting -- so NetBeans is building the file but it doesn't get
into the output. Thanks for investigating!

I guess NetBeans is being picky about what it thinks should be an
output of the build, and we need some way to tell it not to throw the
contract files away.

Cheers

David

josemari

unread,
Mar 8, 2011, 7:01:47 AM3/8/11
to cofoja
Yes, I think so, David. Thanks for your support. I'll keep on playing
around with library.

Cheers,
Josemari

José María

unread,
Mar 3, 2014, 4:00:54 AM3/3/14
to cof...@googlegroups.com, wyatt.earp...@gmail.com
I'm actually playing around with cofoja in NetBeans 7.4. Although I get the same error message, I've found a workaround. I've created a new ant build script with just the following lines:

<?xml version="1.0" encoding="UTF-8"?>
<project name="cofoja" default="all" basedir=".">
    <java jar="dist/Cofoja.jar" 
          fork="true">
          <jvmarg value="-javaagent:dist/lib/cofoja-1.1-r150.jar" />
    </java>
</project>

My netbeans project is named 'Cofoja', of course. After cleaning and building my project in the normal way, I just run this script and cofoja works inside the IDE. :-D

P.D.: Sure we need the configurations found in the first message of this thread, too.

Best regards!

Nhat Minh Lê

unread,
Mar 3, 2014, 4:04:38 AM3/3/14
to cof...@googlegroups.com, wyatt.earp...@gmail.com
Hi,

Hm, I'm a bit confused; what is that script supposed to do and when do
you run it?
I don't remember exactly what your situation is.

Nhat
> --
> You received this message because you are subscribed to the Google Groups
> "cofoja" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cofoja+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

José María

unread,
Mar 3, 2014, 4:10:59 AM3/3/14
to cof...@googlegroups.com, wyatt.earp...@gmail.com
NetBeans deletes the class named 'Stack$com$google$java$contract$H.class' when executing the project. So, I get an error ClassNotFoundException. If I run the project from the command line, there is no problem. This script tries to do exactly this, to run the project from the 'command line'.
Reply all
Reply to author
Forward
0 new messages