Mark Brunson

Greenhorn
+ Follow
since Apr 29, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Brunson

Winston Gutkowski wrote:

Mark Brunson wrote:ok, confirmed doesn't make a difference to override the remove method, same problems, doesn't catch the null in my shell class:


Hmmm. Not quite sure what to suggest then. It may be worth pointing out that there are at least two more update methods: removeAll() and retainAll(). For completeness, you should also override contains(), containsAll(), indexOf() and lastIndexOf(), since they all take element values (or collections) too.

The fact is that NPE is a very simple error: something, somewhere is null when it shouldn't be. It's tracking down the 'where' that can be an absolute sod.

Good luck.

Winston



thanks

I added those methods too, no difference. As far as I can tell I've proven that no null values are ever added to the list or compared to the list, so the problem must be something else. Maybe access from multiple threads at the same time can cause undefined behavior in arraylists like this without throwing an exception? Any other ways to produce undefined, unchecked behavior with an arraylist?
11 years ago

Winston Gutkowski wrote:

Mark Brunson wrote:...and changed the variable to this class instead of ArrayList. There has been no change in the problem; nullError() is never called, but o==null still sometimes evaluates to true in the equals method while ArrayList tries to remove an element.


I don't see a remove() method. Did you write one? I thought the whole point of your test was to make sure that no List update method could be supplied a null value.

Winston



I will do this and test it, but I do already check if the variable being removed is null before using it.

edit:
ok, confirmed doesn't make a difference to override the remove method, same problems, doesn't catch the null in my shell class:
11 years ago

Winston Gutkowski wrote:

Mark Brunson wrote:I mostly just want to figure out why null objects are getting into the list in this particular instance, because it seems impossible and I want to understand what's going on. I don't have an intrinsic problem with nulls being there, I'm just confused that they are.


Fair enough.

Well, assuming that your code uses Lists, rather than ArrayLists (as it should), I still reckon you could use a NoNullsList as I described above(*) as a test vehicle to work out where it's happening.

You never know, you might even find it useful enough to keep around for other things.

Winston

[Edit] Actually, if you define it as I described, you should be able to substitute it for an ArrayList as well.



Ok, I've done this:



and changed the variable to this class instead of ArrayList. There has been no change in the problem; nullError() is never called, but o==null still sometimes evaluates to true in the equals method while ArrayList tries to remove an element.


Jeff Verdegan wrote:Also, just as a side note, from the small bit of your code that I've seen, it looks like you're in the habit of doing a lot of null checks. I'd get out of that habit. It clutters your code for no real benefit. There are certain cases where you want to test for null and log an error and continue (such as at major architectural layer boundaries, or when you're processing a bunch of independent things in a loop and you don't want a failure in one to kill the others). Most of the time though, it's best just to let them happen and then go back and fix the bug that caused them in the first place.

Or maybe you just added them as part of your debugging process, which is fine.


Yeah, it's just for debugging. I'm trying to figure out how a null value is slipping into the list.
11 years ago

Winston Gutkowski wrote:

Mark Brunson wrote:The code I posted in that last post there is from the java.util.ArrayList source, which shouldn't really have any bugs in it right? If I didn't put a null value into an ArrayList, it shouldn't be calling my equals methods with null values as parameters right?


Right, but how are you preventing that?



The add method for that variable is only called in one method, and the parameter of that method is checked for being null before it is added. The reference to the variable is never stored in another variable.


ArrayList certainly doesn't; as you'll discover if you look at the contains() method docs.

Also, equals() seems an odd place to be putting this sort of logic, since there's nothing intrinsically wrong with comparing an object with null.

Have you considered extending ArrayList to define a List that doesn't allow null values to be added, or a null value to be supplied to remove()?



I mostly just want to figure out why null objects are getting into the list in this particular instance, because it seems impossible and I want to understand what's going on. I don't have an intrinsic problem with nulls being there, I'm just confused that they are.
11 years ago

Matthew Brown wrote:Maybe I'm not being clear, or I'm misunderstanding you. But take this case:
There are two things that could cause a comparison with null here.

- list contains null
- x is null

You appear to have ruled out the first one, unless you're missing something. But what about the second? That's what I was getting at - what about the w in your second code snippet? Have you confirmed that is not null?



Oh. Yes I have, this is the code surrounding it:

11 years ago

Matthew Brown wrote:

Mark Brunson wrote:the problem I'm talking about here is that o==null evaluates to true. On the line in ArrayList (in the remove method) pointed to by the stacktrace, the parameter it passes is


Which could still be null - array entries are null until they are populated. Have you checked that it isn't?



The code I posted in that last post there is from the java.util.ArrayList source, which shouldn't really have any bugs in it right? If I didn't put a null value into an ArrayList, it shouldn't be calling my equals methods with null values as parameters right?

I could always just return false when this happens, but it's just so weird and completely outside my understanding that I'm worried something in my code is really broken. I can't think of a way that what is happening would be possible.
11 years ago

Matthew Brown wrote:A null in the list isn't the only possible explanation (as you've explained it). How about the object you're trying to remove? Can that be null?



the parameter of the equals method is definitely null; the problem I'm talking about here is that o==null evaluates to true. On the line in ArrayList (in the remove method) pointed to by the stacktrace, the parameter it passes is
11 years ago
My program keeps occasionally running into a null value in parameter of the equals method of an object when I call the remove method on an arraylist.

This arraylist should not have null values in it. When the equals method notices the null value, and then prints out the list, the null value is never in the list anymore.

When I have Netbeans 'find usages' of the arraylist, the variable reference is never copied over to another variable, and the add method is only in one place. The program checks here if the object added is null, which it never is, and the object is a method parameter, so it shouldn't be possible for another thread to change it to null at that point right?

Any idea how this is possible or how I might figure out what's going on?

equals method (sometimes o==null, but null never shows up when printing the arraylist):


the call that triggers the equals method, according to the stack dump:


only place where .add is called on activeObjects (never throws an exception):
11 years ago

Campbell Ritchie wrote:Unzip the jar and read its manifest file. You can find out about manifest files here.



Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_02-b13 (Oracle Corporation)
Main-Class: mypackage.MainClass

Is there a simple way to get this to include classpath information?
11 years ago

gurpeet singh wrote:to be able to run a jar file by clicking on it you require an executable jar . also the jar in question should have main method. that is but obvious. when you compile and build project in netbeans it automatically creates executable jar of your project in dist directory of your project folder. this is one way. you can also manually make executable jar file by adding manifest file with Main-class attribute. for that you need to refer some tutorial on the internet.



This is how I have been doing it for a while (netbeans method), and it worked pretty well. However for some reason this doesn't work anymore, and I get the error I mentioned (noclassdeffound) when I try to run it by just clicking. It definitely has all those other things because I can run it from the command line if I use a command that first sets the classpath manually, which it shouldn't if the jar wasn't executable or didn't have the main method set correctly.
11 years ago
So a while ago something happened that caused all of the jars I create using netbeans that use external libraries to give me the error 'Exception in thread "main" java.lang.noclassdeffounderror' when run. If I run them from the command line with the command 'java -cp "lib/library.jar;MyJar.jar" mypackage.MainClass' it will run, so I'm pretty sure somehow the lib folder is not being added to the classpath.

I also tried compiling it with a custom ant script, but that didn't fix anything.

How can I get my jars to run by just clicking on them?
11 years ago


I'm really confused by this. When I run this program in VMWare running windows 7, with the mouse cursor over a particular application, nothing happens. In all other situations, the program clicks the mouse when you run it (when the mouse isn't over the application in the virtual machine, when used anywhere outside of the virtual machine).

What could be causing this? How can a Java generated mouse click consistently not work when a manual click does work? Are there any workarounds that might bypass whatever is going on here?
11 years ago
setPreferredSize does fix my issue, thanks! The reason for all the overridden methods in CustomDrawing is that I'm actually using a much larger, more complicated class that frequently updates instead, I just wrote this one to have something simple to represent the problem I was having without tons of irrelevant code.
11 years ago
I'm trying to add my own implementation of jpanel to another jpanel, in a scrollpane, so that as it adds more it will make a list of them down the screen. Unfortunately I can't seem to put space between my jpanels; when I set the second two gridlayout parameters, parts of them get cut off (so that they appear shorter vertically). Any idea why this is happening or how to get around it?

(called from a method in a jframe class)

custom drawing panel
11 years ago