- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Oops, sorry, du-uh. Never mind ...
Admin
If you're really disgruntled and want to cause headaches for your replacement, just write the app in LabVIEW.
Admin
Well that must have been embarassing.... how does "< 0.1" happen 90% of the time?
Admin
Why -127..128? Shouldn't that be -128..127?
Did that in an interview. Repeatedly. While stubornly resisting all hints to the contrary. :(
Admin
I have to say, it would be an interesting challenge to try to come up with a program the does something both useful and predictable, that includes this sort of transformation! To 'interesting' for me to try though.
Admin
This has to be embedded deep in Diebold's software...it's the only explanation...
Admin
I'm fairly impressed! I mean, I see a lot of bad things around here but this is over the edge.
Admin
But that is a great teaching device: how to debug spurious interaction. Have to put this to a debugging exercise in a programming class.
Admin
Yes yes, this is all great. What my boss wants to know is "Will this make my system run much much faster?". I promised him 90% improved performance.
Admin
The total could also be 42 + (3 + 1) = 46
Admin
Hah - that comment is wrong. The actual probabilities are:
-1 for a comment that incorrectly describes what the code is doing. That's why I don't leave comments ;-)
Admin
As others have mentioned - the same 90% of the time, i+1 9% of the time, 42 1% of the time.
You shouldn't have left this comment either.
Admin
I've written something more WTFy :) : https://gist.github.com/988502
Admin
Not entirely sure, but I think that if you add the following code to the class, it will auto-start:
Admin
Hmm, that should be (new ValueMunger()).start(); Gotta love those static blocks!
Admin
-1 for not hiding the call to intValue in some implicit conversion. -1 for not using some of the more advanced language features like Actors and pattern matching
Admin
Try the Console.Beep function in VB...
Admin
I was a bit skeptical at first, but this code is pretty clever and should actually work!
The static valueOf() method of the Integer class often returns cached Integer objects that represent frequently requested values. I do believe that the code above will only work when the valueOf() method is actually used. This is not unlikely, however, since auto-boxing operations (like inserting an integer into an ArrayList) insert calls to this method implicitly.
The fact that valueOf() returns values that are used elsewhere in the program is okay under normal circumstances, since Integer objects are immutable (they cannot be changed), so an Integer representing the value 5 will always have the value 5 throughout its entire lifetime.
However, the line "field.setAccessible(true)" circumvents this and enables us to change the value of a cached Integer object.
Very clever indeed!
Admin
Ha! I fixed one of these. We've got a Currency class hanging around in the app since the jdk1.1 days. Some bright spark decided to make it mutable and some even brighter spark decided to use said mutators to change the value of Currency.ZERO.
Admin
Ha! I fixed one of these. We've got a Currency class hanging around in the app since the jdk1.1 days. Some bright spark decided to make it mutable and some even brighter spark decided to use said mutators to change the value of Currency.ZERO.
Admin
Finally was irritated enough by people fucking this up repeatedly:
By Monte Carlo simulation, after a million rounds, it is:
i 89.9694% 42 1.0095% and i+1 9.0211%
Admin
The single worst time I think any coder has is debugging an intermittent issue. This will certainly cause that, since every execution (which occurs once-a-second) will mess up the system in a different way.
One suggestion for a conceptual improvement I have, if you really want to drive a developer nuts; make the call to ValueMunger.run() (and, look CLOSELY; it IS "run()") randomly do nothing (say a 70-80% chance). That way, the code is stable enough that there's a chance it would make it through Q.A. into the field.
Wow... I always thought it was just physicists who were trying to make a bigger-and-better bomb with the intent it would never be used. Does that make me a physicist?
Admin
Brillant!
Though I think it would be a little better if it would run, say, once a day, leave the values messed up for 10 minutes, and then put them back.
That way the user would complain, but when the programmer came along to test it, everything would probably work correctly. Bugs that can't be reproduced are very difficult to track down.
Admin
OK, I've updated it. It is still at https://gist.github.com/988502 .
Admin
Its like FORTRAN IV all over again.
Admin
Those totals come up to 101%, I believe the +1 only happens 9% of the time.
Admin
This one could easily be made much, much more annoying by adding a check so that it only runs in a release build, not in debug mode. Then, everything runs just fine in the IDE, then when you deploy it, things go bananas.
Admin
I tend to avoid all non-beverage, non-island forms of Java.
So can someone tell me why on earth the computer language by that name needs to cache values of an integer? Shouldn't those be completely invariant? (Or, to be more precise, Integer, because, apparently, they are different things. I still don't quite understand that concept despite my best efforts.)
Admin
Admin
This tidbit does not do much to improve my impression of the Java language. I would go so far as to say that there is something fundamentally erroneous with a computer system where the meaning of integer values is or can be mutable.
(Maybe all those assert(0 == 0) lines have some legitimate use after all!)
Admin
There is a distinction in Java between the atomic primitive of type 'int' and the object class of type Integer. An int is an int, it's not redefineable, and it behaves the way you'd expect an int to behave. Integer is a wrapper class with an int as one of its member fields, and the value of that member field can be changed. This code does not affect math with ints, nor methods that take only ints as parameters, only those that (implicitly or explicity) convert an int primitive to an Integer Object.
This may be done to get at various methods defined in the Class(utility classes to manipulate the number bitwise, express the integer in different formats, such as hexadecimal or octal,and so forth), or to easily allow an integer to be passed by reference where that behavior is desired. Once this is the case, Integer objects are cached like any other object.
Admin
TRWTF is "give programmers enough rope to shoot themselves"
Admin
There is a serious problem with a construct that claims to convert an int to an Integer object where the int-value of that Integer object is not guaranteed to be the value of the int from which it originated, mostly because of the connotation of the name Integer.
Admin
It's not supposed to be accessible. But the setAccessible(...) method makes it accessible.
They should've installed a SecurityManager to prevent that field from being accessible...
Admin
Admin
Ahhh lovely stuff, Dr Heinz Kabbutz recently took an audience at Geecon through a masterclass in this sort of Java munging. 1/2 of the audience was mesmerised, the other 1/2 were weeping in terror :D
Admin
Its great Ba.. I will add this for next release
Admin
Are you Harshal Gawande?
Admin
Two things. First, as several people have mentioned, it's not a primitive, it's a boxed object, so if you're using int you're probably safe for the most part. Second, this code would only work on signed or trusted code, so if you tried to do this in for instance an applet (I know, who even uses those anymore, oh the stories I could tell), it would throw an exception on the call to "field.setAccessible( true );".
Admin
Probably won't work, value is final, and even reflection can't edit final fields. But you can modify IntegerCache.cache.
Admin
Does somebody care to explain this code and why does it work for non-.net programmers? how can you change the value of ints?
Admin
Now, this is just plain evil. Just set this up to fire after some time in order to pass all tests and get it into production code.
Admin
Best way to detect is to install a SecurityManager. Even without, setAccessible(true) should ring alarm bells…
Admin
It exists so persistence managers and debugging tools can do their work.
Admin
The main Achilles heel is that it effects the code base immediately, which makes it trivial to detect. To avoid this you should consider making it a scheduled event. Preferably several days after start with random factors. Also consider restoring the original state after a certain amount of time. This way it can be turned into a quasi-Heisenbug.
Admin
Is this still working on modern Java (e.g., JDK 11)?
I'm trying to have it working but it sticks on 5, even if the a+b part is put in a while.
Admin
Is this still working on modern Java (e.g., JDK 11)?
I'm trying to have it working but it sticks on 5, even if the a+b part is put in a while.