Sudden failure of old code

B

Bob

I changed a URL in a .java file, in a string that is not used in any
logic, recompiled, and now I get a NullPointerException on a completely
different line.

Now, even working from a backup of the code, I can't get it to work anymore.

Any idea why recompiling old code would cause it to suddenly fail, even
though it was working fine on modern JREs beforehand?

I'm struggling to figure it out.
 
G

G. Ralph Kuntz, MD

This phenomenon is known as "Bit Decay" or "Software Rot" -- "I didn't
change a thing, but now the code doesn't run".

:)
 
K

Knute Johnson

Bob said:
I changed a URL in a .java file, in a string that is not used in any
logic, recompiled, and now I get a NullPointerException on a completely
different line.

Now, even working from a backup of the code, I can't get it to work
anymore.

Any idea why recompiling old code would cause it to suddenly fail, even
though it was working fine on modern JREs beforehand?

I'm struggling to figure it out.

The problem is in your code!
 
?

=?ISO-8859-1?Q?Daniel_Sj=F6blom?=

Bob said:
Any idea why recompiling old code would cause it to suddenly fail, even
though it was working fine on modern JREs beforehand?

A possible reason is that the code you were running is not the code you
are looking at. Ie. somebody messed with the source and didn't bother to
recompile. IIRC, Roedy Greene mentioned this as an unbeatable way to
confuse maintenance programmers ;-)
 
P

Patricia Shanahan

Bob said:
Any solutions?

Bit rot can be reduced by frequent polishing. Recompile and
run your full test suite regularly, regardless of whether
you intended to make any changes or not.

Remember, the default state of all programs and processes is
failing. Things only work because they are being forced to
work. If you have not recently recompiled and regression
tested, don't expect it to just work.

As far as your immediate problem is concerned, remember to
look for changes in the environment, such as missing files,
as well as changes in the source, classfiles, compiler etc.

It is often easier to debug the problem from first
principles. Once you know the immediate cause of the
NullPointerException you will probably know how it happened.

Patricia
 
R

Ross Bamford

I changed a URL in a .java file, in a string that is not used in any
logic, recompiled, and now I get a NullPointerException on a completely
different line.

Now, even working from a backup of the code, I can't get it to work anymore.

Any idea why recompiling old code would cause it to suddenly fail, even
though it was working fine on modern JREs beforehand?

I'm struggling to figure it out.

Here's another idea, in case source decay doesn't appeal. This is just
an idea, I don't know if its true or not, but I'm sure I'll have the
answer in half an hour or so ... ;)

What if something was changed, say between 1.2 and 1.3, such that a
method that previously didn't now *does* throw NPE. Alternatively, a
method that never returned null maybe now does.

So the JVM, when loading a class, looks at the target, and 'emulates'
the old behaviour if needs be. But now your new classes have a modern
target, it won't do that anymore.

An easy way to check this would be to compile with -target 1.2 (or
appropriate - whatever the old one was compiled with). If it works, you
need to find the deprecated usage.

If you do try this, I'd be interested to hear your results - as I say I
don't *know* that this goes on, and am not inclined to go surfing the
source to find out...
 
C

Chris Uppal

Ross said:
So the JVM, when loading a class, looks at the target, and 'emulates'
the old behaviour if needs be. But now your new classes have a modern
target, it won't do that anymore.

The JVM has no provision for emulating previous versions of the library.

-- chris
 
R

Ross Bamford

Ross said:
So [perhaps] the JVM, when loading a class, looks at the target, and 'emulates'
the old behaviour if needs be. But now your new classes have a modern
target, it won't do that anymore.[?]

The JVM has no provision for emulating previous versions of the library.

-- chris

I guess it would be ridiculous to manage such a strategy, especially by
Java v26.12 :)
 
B

Bob

Bob said:
Any idea why recompiling old code would cause it to suddenly fail, even
though it was working fine on modern JREs beforehand?

I'm struggling to figure it out.

Well, I don't get it, but the problem vanished.

Without doing anything further, it seems to have resolved itself.

One thing I did notice was that the code worked fine when using
AppletViewer, but viewing the Applet using Mozilla or Opera caused the
NullPointerException. Now that exception has vanished and all works
fine, even though I did nothing further to the code.

Maybe it was a cacheing issue, but that doesn't explain why the code
wouldn't work on a local copy.

Thanks for your help, those who offered advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top