LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-12-2022, 01:11 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Rep: Reputation: 110Reputation: 110
Geany prints stale content of compiler


Code:
public class Main{
	public static void main(String args[]) {
	System.out.println("Hello, World");
	
	String name = "John";
	System.out.println(name);
	
	int myNum = 18;
	System.out.println(myNum);
	}
}
I run the Run command. It's a custom command:

Code:
javac "%f"; java Main
The output:

Code:
javac "Main.java"; java Main (in directory: /home/devel/java/First)
Hello, World
John
18
Compilation finished successfully.
OK.

So I changes the code:

Code:
public class Main{
	public static void main(String args[]) {
	System.out.println("Hello, World");
	
	String name = "John";
	System.out.println(name);
	
	int myNum;
	System.out.println(myNum);
	}
}
I suppress the value of myNum to see how Java handles uninitialized values.

The output:

Code:
javac "Main.java"; java Main (in directory: /home/devel/java/First)
Main.java:9: error: variable myNum might not have been initialized
	System.out.println(myNum);
	                   ^
1 error
Hello, World
John
18
Compilation finished successfully.
It points out the error, but it still prints the old content including the no longer valid value 18.

Can that behavior be changed? I don't want to see that old value or, even better, print nothing beyond the error message.
 
Old 09-13-2022, 06:26 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
That is a random value. Occasionally it can be identical to the old value (as long as it is not overwritten), but otherwise unpredictable. Try to close geany completely, run a browser or something new app and restart it again. I'm sure that 18 will be changed.
And yes, you can change that behavior: you must not use uninitialized variables, assign a default value (if you wish).
(and it is not stale content of compiler, but the random value read from the RAM).

Last edited by pan64; 09-13-2022 at 06:27 AM.
 
Old 09-13-2022, 07:43 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

I doubt it's a random value, it's more likely to be the hard-coded value from the previously compiled class which is still being executed because compilation failed (and thus didn't replace the class), and the custom run command does not make execution conditional on successful compilation.

 
Old 09-13-2022, 08:50 AM   #4
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by pan64 View Post
And yes, you can change that behavior: you must not use uninitialized variables, assign a default value (if you wish).
You don't understand. Whether my code is right or wrong is not the point. I knew it was wrong when I wrote it. The point is I want Geany to print nothing besides the error message whenever there is a compilation error.

Quote:
Originally Posted by boughtonp View Post
and the custom run command does not make execution conditional on successful compilation.
Can the custom command make execution conditional on successful compilation? Do you know how?
 
Old 09-13-2022, 08:57 AM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

Your LQ history shows you've been working with command line for well over a decade. Do you really need to be told how to do this?

(If so, maybe you should spend some time reviewing the Bash manual...)

 
Old 09-13-2022, 09:35 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
If boughtonp is right in post #3 you executed the compile and run in one step. Therefore the new compilation failed, the old code was executed again.
It looks like I missed it.
Code:
javac "%f"; java Main
So if you want to do it differently just do it differently.
 
Old 09-13-2022, 01:42 PM   #7
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by boughtonp View Post
Your LQ history shows you've been working with command line for well over a decade. Do you really need to be told how to do this?
(If so, maybe you should spend some time reviewing the Bash manual...)
OK, gumshoe. But tweaking that command line wasn't working the way I expected. A simple '&&' wouldn't do the trick.

So I had to write a script:

Code:
javac $1
output=`java Main`;
if test $? -eq 0; then
	java Main
else
	echo "ERROR"
fi
And it's not Bash, it's sh. I avoid Bash whenever possible because reasons.

It works, but I'm not very happy with the fact that I am running 'java Main' twice. Can that code be shortened?

Yes, I need to be told how to do this. Please.
 
Old 09-13-2022, 02:39 PM   #8
rclark
Member
 
Registered: Jul 2008
Location: Montana USA
Distribution: KUbuntu, Fedora (KDE), PI OS
Posts: 487

Rep: Reputation: 180Reputation: 180
Why the drama here? Why not just do your compile as step 1, and if successful, run it as step2? No need for shell scripts and such....

1) compile it
> javac abc.java

If successful then run it. Otherwise fix the problem and recompile.

2) run it
> java abc
 
Old 09-13-2022, 03:05 PM   #9
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by rclark View Post
Why the drama here? Why not just do your compile as step 1, and if successful, run it as step2? No need for shell scripts and such....

1) compile it
> javac abc.java

If successful then run it. Otherwise fix the problem and recompile.

2) run it
> java abc
Geany requires a one liner. Using a script gives me more lines. The first line will compile it but will not generate any output. It's the second line that generates it.
Attached Thumbnails
Click image for larger version

Name:	geany.png
Views:	8
Size:	50.5 KB
ID:	39581  
 
Old 09-14-2022, 09:37 AM   #10
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by lucmove View Post
Geany requires a one liner. Using a script gives me more lines. The first line will compile it but will not generate any output. It's the second line that generates it.
Then I would suggest that you skip using the geany gui and do the compile from the command line so you are able to see any error messages. After a successful compile then use geany if you wish
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adobe Reader 9 prints all, Evince 3 prints nothing Michael Uplawski Linux - Software 1 07-16-2016 01:36 AM
LXer: Geany - A Perfect Programming IDE LXer Syndicated Linux News 0 04-25-2007 07:01 AM
LXer: I dream of Geany LXer Syndicated Linux News 0 04-06-2007 03:01 PM
CUPS Printer Problem - prints, but prints gibberish Sparrowhawk Debian 2 06-19-2006 07:32 PM
cups prints poorly, while lpr from command line prints well spindles Linux - Software 2 04-01-2006 04:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration