Month: March 2013

  • A trapdoor in Apache Commons CollectionUtils (and its docs)

    A few days ago I hit a problem while refactoring some legacy Java Code. Following my own advice to [use safe and simpler library methods][1] I changed the code-block

    List
    list = dao.getEntries(id); if(list != null && list.size() > 1) { doFancyLogic(list); } to List list = dao.getEntries(id); if(CollectionUtils.size(list) > 1) { doFancyLogic(list); } Should do the same, looks nicer and should be safer too, right? Imagine my confusion when suddenly several unit tests began failing at other parts of the code not directly related to this change. When I found out that this single line was the cause of the other errors I of course looked up the JavaDoc for CollectionUtils on Google. According to the docs at the size() method should return 0 when presented with a null collection. Things were very strange here. In fact, it took me a few days to find out what’s wrong. In fact, I did not recognize that the access to the JavaDoc was redirected to , which did not show the documentation of the latest stable CollectionUtils docs (as it did until a few weeks ago) but showed the version of the SVN tip. It took a roundtrip through the Apache Commons main page to find the correct JavaDoc page for the current stable 3.2.1 CollectionUtils at . And, surprise surprise, there the API for the size() method looks a *bit* different: “Throws: java.lang.IllegalArgumentException – thrown if object is not recognised or null”.
    Well, so much for the praised null-safety of Apache Commons… In the current implementation, CollectionUtils.size() is of no use for me and I reverted the refactoring. In the end I was a victim of partly my own assumptions for the null-safety of Apache Commons and partly a very weird redirection of the Google search result URL. I still have no idea why this URL suddenly gets redirected to a different version than it did until a few weeks ago but I hope that either Google soon updates its search result (unlikely as there are loads of references to this address) or Apache corrects it to its former destination. For the safety of users in my opinion the correct version which shows up should be the one of the latest stable version, not an arbitrary SVN version. Lesson learned: also check version of JavaDoc if something smells fishy, even if it has been correct in the past. [1]: http://kosi2801.freepgs.com/2010/10/02/java_tip_9_use_collectionutils_for_evaluation_and_manipulati.html “Java Tip #9: Use CollectionUtils for evaluation and manipulation of Collections”
  • Repurposing an ATX Power Supply

    For my LED Cube Project I already hinted that I may use an old ATX power supply as repurposed power source. In the past two weeks I found some evening time to work on that subproject. The plan was to use an old ATX power supply which I had left from old computer parts and equip it with banana sockets to make the common PC voltages easily available to use for my electronic projects. This repurposing seems natural as the voltages available from PC ATX power supplies are the same which are most commonly used in hobby microelectronics (3.3V, 5V, 12V). Additionally these devices provide a high stability and current capacity as they have to offer those requirements for stable computer operations which demand extremely fast switching load capability and still let the PC rely on a stable supply.

    I found several resources on the internet which explained how to refit an old ATX power supply to offer nearly stabilized Lab Power Supply capabilities. It seemed not too hard and I decided to use the information from that descriptions to add the banana sockets, status LEDs and the switch directly into the metal case of the power supply itself. From the pictures on the internet that seemed possible without much problems.

    Since that is now finished and (surprisingly?) working as expected I’d like to share my experiences.

    Update 2013-03-08
    I did not use fuses for the power lines when modifying my PSU. In theory the PSU should turn itself of in case of shorts but there may still be the possibility for very high currents during a short period of time. It is highly advised to add properly sized (check the rated max current) fuses to each supply current line!

    This was the old power supply which I could scavenge from a retired computer.

    From ATX Power Supply Repurpose

    From the outside it looked pretty innocent. During my preparation research I learned that ATX power supplies have some characteristics which have to be considered during modification and utilisation of the electronics.

    • altough there is a standard for ATX power supplies, some supplies do not meet certain requirements (esp. behavior in edge cases)
    • activation is pretty easy, just connect PS_ON (green) to GND
    • to provide stable voltages many power supplies require a certain minimum load
    • power supplies are not guaranteed to be short-safe
    • a signal on the PWR_OK line does not guarantee a stable power source (especially on cheap supplies)
    • stored leftover energy in the power supply can be lethal, so extreme caution is highly recommended

    To find out the exact behavior of my power supply I tried out various connectins and measurements directly on the ATX connector. As the side of the supply told it was capable of up to 22 Amps on the 5V line so I’ve been already very careful here and checked the ATX connector layout several times to prevent accidents and violent reactions within my hands. I’ve been a bit nervous during that measurements that’s maybe also the reason why I forgot to take photos of this. Well, I learned following from these tries:

    • PS_ON is really easy to control
    • my power supply also requires a minimum load
    • the PWR_OK signal works as expected
      • no PWR_OK without load
      • PWR_OK turns off again if load is removed later on
    • the standby lines keep their voltage quite some time after disconnecting the supply from main power, indicating a high internal capacity

    Before I decided to rip open the guts of the supply, I left the box sitting unconnected for two days to be absolutely sure that I’m not suprised by some leftover charge. After two days the box was stripped naked.

    From ATX Power Supply Repurpose

    The open supply made me realize some additional but unexpected problems. Firstly there was much less space available for additional wires.Secondly the space on the front panel was obstructed by heatsinks. Therefore it would be a pretty limited working area and I also had to place the banana connectors between the heatsinks. Luckily at least all cables were properly colored and even correctly annotated on the PCB. So I continued and marked the locations of all additional components on the frontplate.

    From ATX Power Supply Repurpose

    During my tests on the breadboard I realized that load resistors (I used two 5Ohm/5W ceramic resistors in serial) get quite hot when connected to power, so I decided to not have them dangling around in the box but clamp them tightly on one of the heatsinks. Checked, that this solution also fits in the tight space with the banana connectors and wires in place and continued to the next step: drilling the holes in the front plate.

    From ATX Power Supply Repurpose

    I chose the size of the holes by measuring the dimensions of the banana sockets, LED covers and the switch with a caliper. After that I drilled smaller ~1mm holes to better be able to control the position during drilling and re-check the dimensions and gaps between them. During that I had to reposition the holes for GND and 12V as I did not initially take onto account the metal bridge of a hanging transformator, which I removed for the work, behind it. After that I extended each hole to its final size with the correct drill.

    Quickly after beginning the first hole I saw that the case was thicker than I anticipated and much more flings built up than I expected. I was worried that these could pour into the power supply and cause unpleasant surprises when they survived the final cleaning between the contacts on the supply board. During drilling I could only make sure that the outer side of the drilling holes did not spray flings into the case so I folded up some newspaper pieces as protection and sticked them tightly on the back of the holes to catch all flings which would otherwise fall into the PSU on the inside during drilling. This worked remarkably well.

    From ATX Power Supply Repurpose

    After the holes were finished I began to mount the status LEDs, the power switch and the first two banana sockets.

    From ATX Power Supply Repurpose

    Also the load resistors were soldered together, clamped on the heatsink and, as almost everything I mounted inside the PSU, protected by maybe a bit too much shrink tubing.

    From ATX Power Supply Repurpose

    With the more complex wiring in place I continued with the connections to the remaining voltage sockets which should not take too much time. At least that’s what I thought. In reality connecting the remaining four voltages caused much more trouble than the first part. The main problem for me was that I initially tried to always connect all available wires for a certain voltage rail to the banana socket. I failed with this target as it was very difficult to screw the wires onto the sockets in the very tight working area between the components of the PSU. Furthermore the thick pack of wires were squeezed out of the screwings when they were tightened. In the end I decided to only connect two or three cables to the sockets, clip off the rest and isolate those with shrink tubing. For the 3V3 connection one of the cables I connected was the brown 3V3_SENSE connection which is necessary for a stable 3.3V supply voltage.

    Another problem was that the black shrink tubing was very difficult to get over the socket connectors when the cables were in place but with a lot of fiddling I managed to pull all of them over the sockets and properly isolate the power rails.

    From ATX Power Supply Repurpose

    Finally I cleaned out the PSU with a compressor and lots of air, did a thorough visual inspection of the modifications and the board, re-installed the initially removed transformer and closed the case of the PSU. The ATX bench power supply in its final beauty:

    From ATX Power Supply Repurpose

    After carefully plugging in the PSU and using a rubber glove to turn on main power on the backside I did a quick check if the case was free of erronous current. Then I again carefully turned on the new switch on the front, checked the safety of all metal parts once more and finally did a touch-test if it’s really safe to the bare hand. Being confident that everything was OK and the LEDs correctly indicated the status I took a check of the voltage levels on the sockets with the multimeter.

    From ATX Power Supply Repurpose

    My multimeter showed all voltage levels to be within acceptable limits (11.7V, 5.1V, 3.4V, -5.1V, -11.4V) and without any fluctuation. I therefore consider this PSU repurposing sub-project a complete success. What’s still left is to stick rubber bumpers on the bottom of the PSU and add properly printed annotations to the elements on the front instead of the pencil writing. But since I don’t have any of that around that’ll have to wait a few more days.

    If you’re interested in more images, there are many more available in the album which also show the progress in a bit more detail and from different angles. Included are also some shots of the mess on my desk during the project and an accident with a banana socket where it broke when I tried to screw it tight with too much wires.

    Some resources for those who are interested (sorry, most of them are German):

  • Using Keywords in Firefox for fast navigation and instant search access

    Just to share a small tip which over time has saved me lots (really, lots of lots) of time.

    It is possible in Firefox to define a bookmark as a shortcut which can be entered in the URL bar of the browser. So for example if you often visit a certain webpage with a long or complicated URL, e.g. https://en.wikipedia.org/wiki/Star_Trek:_The_Next_Generation you most certainly add it as a browser bookmark at some point. Maybe you even put that bookmark on your favourites bar so that you only have to travel a short distance with your mouse to open the page.

    A browser bookmark already saves a lot of time but there is still some more potential to speed it up and this is where URL shortcuts enter the stage. To be honest it’s not only the shortcut alone but a combination of a keyboard shortcut and URL shortcut. But first things first.

    To define a bookmark to be available as URL shortcut you have to enter the Firefox bookmark manager. Then navigate to the bookmark and click it. Its properties are now shown in the lower part of the window. To define an URL shortcut for it click on "More" and a line "Keyword" should appear. Whatever word you enter here is later an alias for this URL in the browser. For example you could enter "st" in the bookmark for the Star Trek URL above. From now if you just enter "st" in the browsers URL bar, https://en.wikipedia.org/wiki/Star_Trek:_The_Next_Generation is loaded.

    This is fast but still not much faster than clicking a bookmark. To make it really faster you have to activate and enter the URL bar by using the keyboard shortcut CTRL-L. CTRL-L and entering "st" should now really be faster than moving the mouse if you’re just a bit experienced with touch typing on a computers keyboard.

    But wait, there’s more!

    If you have defined a keyword for a bookmark it is possible to supply parameters to this bookmark. This work by using "%s" at the portion of the URL which should be replaced by anything which you write after the URL shortcut into the URL bar.

    For example if you dislike the CTRL-K keyboard shortcut to jump to Firefox’ search box you could decide that you want https://www.google.com as the keyword "g". Edit this bookmark again and change the bookmarks URL to be "https://www.google.com/search?q=%s". Now you can also add the search queries to the URL shortcut/keyword on the URL bar. Entering "g star trek" should provide lots of joy to the average trekkie 🙂

    At work my favourite URL shortcuts are defined as following:

    • ora -> http://%s.ora-code.com for quick access to explainations of Oracle error messages. Eg. entering "ora ORA-01455" leads to a good explaination of the cause of this error.
    • leo -> http://dict.leo.org/ende?search=%s translates german or english words into the respective other language.
    • wiki -> https://www.wikipedia.org/wiki/%s is a shortcut to the Wikipedia article. Most words are already directly available on wikipedia so this works 90% of the time for me.

    Many webpages offer a search functionality and if you want to make this accessible in a very quick way just look how the search results page URL is composed and replace the portion of the search term whith %s for your bookmark.

    Simple, fast, unbelievable effective.