Wednesday, September 1, 2010

ADF code corner moved

OTN has been undergoing a change and therefor all links and references changed.
The ADF code corner can now be found at the following link:

http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html

This is a site with as-is coding examples of ADF

Friday, February 12, 2010

Usage of equals in Java

Every now and then I take a look on a projects java source code on the web.
I still am amazed that most of that code do not use some basic coding rules.

One of these is to check objects with equals to a static string.
This is mostly done as:

private static final String STATIC_TEXT = "Static Text";

if(object.equals(STATIC_TEXT)
{
.....
}

The though part about this is that people do not see the danger in this.
The fact is that (most) objects in java are initiated with null if.
So the case shown above could result in an easy nullpointerexception.
While this is not necessary, this could be prevented by changed sequence in which you execute this statement.
<br />private static final String STATIC_TEXT = "Static Text";<br /><br />if(STATIC_TEXT.equals(object)<br />{<br />.....<br />}<br />

When changed like this the exception will not occur, only the check will result in 'false'.
Keep in mind that the code than needs to handle a null object(s).

To prevent that the usual check '!= null' can always be executed.
But by putting the objects in the right order it will prevent a lot of unnecessary searches for errors.
 

Thursday, January 14, 2010

Error using upgrade assistant in JDeveloper 11.1.1.2.0

Today I was running the upgrade assistant in  JDeveloper 11.1.1.2.0 to migrate an ear file to see if we can get a quick deployment on the WLServer.
But then I suddenly received  the following error:


31:57 WARNING - ***
[ERROR] Action in Web Service Artifact Generation 10.1.3javax.script.ScriptException: sun.org.mozilla.javascript.internal.WrappedException: Wrapped java.lang.NullPointerException (<Unknown Source>#10)    at com.sun.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:41)    at oracle.migration.action.ScriptBody.execute(ScriptBody.java:122)    at oracle.migration.action.Action.eval(Action.java:210)    at oracle.migration.action.Action.execute(Action.java:176)    at oracle.migration.action.Action.doAction(Action.java:227)    at oracle.migration.action.Action.doFinally(Action.java:231)    at oracle.migration.action.Action.execute(Action.java:188)    at oracle.migration.rule.MigrationRule.performAction(MigrationRule.java:808)    at oracle.migration.update.Updator$ActionContent.doUpdate(Updator.java:100)    at oracle.migration.update.Updator.doUpdate(Updator.java:110)    at oracle.migration.rule.MigrationRule.doUpdate(MigrationRule.java:788)    at oracle.migration.rule.MigrationRule.doUpdate(MigrationRule.java:781)    at oracle.migration.Migrator.generateArtifacts(Migrator.java:762)    at oracle.migration.MigrationPlan.doMigration(MigrationPlan.java:511)    at oracle.migration.MigrationPlan.execute(MigrationPlan.java:438)    at oracle.weblogic.jdeveloper.migration.io.WLMigrationManager.executeArchiveFindings(WLMigrationManager.java:288)    at oracle.weblogic.jdeveloper.migration.addin.application.ArchiveMigrationContext.regenerateFindings(ArchiveMigrationContext.java:85)    at oracle.weblogic.jdeveloper.migration.addin.application.ArchiveMigrationContext.continueUpgrade(ArchiveMigrationContext.java:131)    at oracle.weblogic.jdeveloper.migration.addin.command.ContinueUpgradeCommand.run(ContinueUpgradeCommand.java:89)    at oracle.toplink.workbench.utility.command.CommandWorker.run(CommandWorker.java:61)Caused by: sun.org.mozilla.javascript.internal.WrappedException: Wrapped java.lang.NullPointerException (<Unknown Source>#10)    at sun.org.mozilla.javascript.internal.Context.throwAsScriptRuntimeEx(Context.java:1699)    at sun.org.mozilla.javascript.internal.MemberBox.invoke(MemberBox.java:147)    at sun.org.mozilla.javascript.internal.NativeJavaMethod.call(NativeJavaMethod.java:190)    at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Interpreter.java:3073)    at sun.org.mozilla.javascript.internal.Interpreter.interpret(Interpreter.java:2239)    at sun.org.mozilla.javascript.internal.InterpretedFunction.call(InterpretedFunction.java:138)    at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(ContextFactory.java:323)    at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(ScriptRuntime.java:2747)    at sun.org.mozilla.javascript.internal.InterpretedFunction.exec(InterpretedFunction.java:149)    at com.sun.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:37)    ... 19 moreCaused by: java.lang.NullPointerException    at java.io.File.<init>(File.java:222)    at oracle.migration.ws.config.cli.SmartUpgradeEntry.createContinuationStateFile(SmartUpgradeEntry.java:285)    at oracle.migration.ws.config.cli.SmartUpgradeEntry.upgrade(SmartUpgradeEntry.java:174)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    at java.lang.reflect.Method.invoke(Method.java:597)    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:37)    at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    at java.lang.reflect.Method.invoke(Method.java:597)    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:244)    at sun.org.mozilla.javascript.internal.MemberBox.invoke(MemberBox.java:132)    ... 27 more[INFO]: script file:
null
script line:

   extraArgs=migrator.getLocator("_cliArgs")
   if (extraArgs==null) {
          map = null;
   } else {
          leaves=extraArgs.getLeafMigrationElements(rule)
          migEl=leaves.get(0)  
          map=migEl.getArtifact()    
   }
          Packages.oracle.migration.ws.config.cli.SmartUpgradeEntry.upgrade(rule, migrationElement, map, targetVersion)
      ot=Packages.oracle.migration.ws.config.cli.SmartUpgradeEntry.getOutString();
          migrationElement.setAttribute("ws.upgrade.out", ot)

 
script code:
null


I did not see this in previous migrations.........

After a while of debugging and looking for certain errors finally it came to mind that spaces in paths of imported files could be disastrous.

The error changed a bit, now it could find de ear but still ended in a nullpointer exception :-(
The fix for this that the whole workspace and project also had a space in the path.
After changing this the upgrade went through and we could continue looking into the migration of all parts for the ear......