How to enable assert

Hello,

I have a project targeting 1.4.1, I checked the Project Properties box
"Enable 'assert' keyword and then restarted IntelliJ.

I then wrote a test program (see below) that has the following line in it:

assert(false) : "This should fail";

I ran this via IntelliJ both in 'release' and in 'debug' mode. I was
expecting to see a message in the IntelliJ output window telling me that the
assetion had failed. I did not see any such message in either release or
debug mode.

Is there something else that I need to do to enable assert other than simply
checking the check box and restarting IntelliJ?

Thanks,

Ted Hill


public class AssertionTestFrame extends JPanel
{

public AssertionTestFrame()
{
System.out.println("AssertionTestFrame.AssertionTestFrame");
assert(false) : "This should fail";
}

public static void main(String[ ] args)
{
JFrame frame = new JFrame("AssertionTestFrame");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane( ).add(new AssertionTestFrame( ),
BorderLayout.CENTER);
frame.setSize(400, 200);
frame.setVisible(true);
}
}


2 comments

You need to use the vm parameter -ea (or -enableassertions)

Add it to the VM Parameters box of the run/debug section of the project
properties. This will cause an exception to be thrown when the assertion
fails.

N.


Ted Hill wrote:

Hello,

>

I have a project targeting 1.4.1, I checked the Project Properties box
"Enable 'assert' keyword and then restarted IntelliJ.

>

I then wrote a test program (see below) that has the following line
in it:

>

assert(false) : "This should fail";

>

I ran this via IntelliJ both in 'release' and in 'debug' mode. I was
expecting to see a message in the IntelliJ output window telling me
that the assetion had failed. I did not see any such message in
either release or debug mode.

>

Is there something else that I need to do to enable assert other than
simply checking the check box and restarting IntelliJ?

>

Thanks,

>

Ted Hill

>
>

public class AssertionTestFrame extends JPanel
{

>

public AssertionTestFrame()
{
System.out.println("AssertionTestFrame.AssertionTestFrame");
assert(false) : "This should fail";
}

>

public static void main(String[ ] args)
{
JFrame frame = new JFrame("AssertionTestFrame");

>

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

>

frame.getContentPane( ).add(new AssertionTestFrame( ),
BorderLayout.CENTER);
frame.setSize(400, 200);
frame.setVisible(true);
}
}



0

Is there something else that I need to do to enable assert other than

simply

checking the check box and restarting IntelliJ?


Did you add the -Dea (and -Desa id you want) to the command line of the run
entry? The running jvm has assertions disabled by default.


0

Please sign in to leave a comment.