This action might not be possible to undo. Are you sure you want to continue?
Here, you'll learn how to investigate and resolve typical OA Framework problems using the debugger. For additional information about this subject, see Debugging OA Framework Applications in the Developer's Guide.
Debugging Lab Goals
After completing this exercise, you should have learned how to: • Use source, method and class breakpoints in local project code, and in the underlying technology stack (OA Framework classes). • Debug three common exceptions: java.lang.NullpointerException, java.lang.ClassCastException and oracle.jbo.SQLStmtException. • Extract salient information from a stack trace. • Read and use the call stack. • Explore application module retention behavior using the debugger. • Navigate the data structures of key OA Framework and BC4J classes using the debugger.
Debug Lab Application Introduction
Here, you'll be working with a special "debug application" that was built to include errors for you to find. Note: This application is optimized for the purposes of this lab. It does not fully comply with BLAF UI Guidelines or the OA Framework coding standards. For example, you'll see some controller code that sets a web bean property that should be set declaratively. The code is included specifically so we can introduce exceptions. This code should not be used as a model for production code. The debug lab "application" is included in the LabSolutions project, and it includes the following components: File Descriptio n oracle.apps.fnd.framework.toolbox.labsolutions.webui.DebugLabSearchPG Search for employees page. Controller for search region. Controller for results region. Create employee page. Controller for create page.
oracle.apps.fnd.framework.toolbox.labsolutions.webui.DebugSearchResults CO oracle.apps.fnd.framework.toolbox.labsolutions.webui.DebugLabCreatePG
toolbox.toolbox.server.labsolutions.framework.toolbox.apps. Page used in state managem ent debug task. View object used in debug create page.framework. Employee entity object.labsolutions.framework.fnd.server.labsolutions.EmployeeEOImpl (and its associated expert. Application module for state managem ent debug task.framework.fnd.DebugBLabAM 3 . Application module for state managem ent debug task.apps.DebugBPG oracle. oracle.DebugEmpSummary VO oracle.webui.apps.toolbox. View object used in debug search page.schema.DebugAPG oracle.apps.server.server.apps.fnd.apps.DebugEmpFullVO oracle.labsolutions.server. Page used in state managem ent debug task.labsolutions.toolbox.toolbox.apps.oracle.labsolutions.framework.apps.fnd.toolbox.webui.fnd.framework.labsolutions.fnd.fnd. validation application module and validation view objects) oracle.DebugLabAM Application module for debug search and create pages.fnd.server.framework.toolbox.DebugALabAM oracle.framework.
Prerequisite Here. ensure that your OADeveloperMode project option is enabled as described in Step 2 of the Hello. you will not be able to access the error stack as intended in this lab. World! lab. If this is not enabled. 4 .
processFormRequest(pageContext.labsolutions.DebugLabAMImpl. Furthermore. • Select the Go button again. run test_fwklabsolutions. World! lab if you need them).Task 1: Investigate Unexpected Code Execution (Part 1) Throughout this lab we ask that you run the test_fwklabsolutions. • When the Search page renders. o In oracle. you'll notice that your processFormRequest method isn't called at all. Tip: You must fix each error in sequence before moving on to the next task. you should do the same because of subtle runtime differences between these methods (launching from a test JSP more closely approximates production deployment).toolbox.jsp instead of running the lab pages directly.jsp in debug mode.server. running the test JSP gives you a convenient stopping point for setting breakpoints before accessing "broken" pages. When you debug your product code. add a breakpoint inside the initQuery method at this line of code: StringBuffer whereClause = new StringBuffer(100). Note that you cannot test your fix (you'll encounter the NullPointerException planned for Task 2). add a breakpoint inside the processFormRequest method at this line of code: super.toolbox. • Select the Debug Lab link when the test page renders.fnd. Can you figure out why this isn't happening and fix it? See the corresponding Task 1 solution if you need help.fnd. For now.apps. • In the LabSolutions project.toolbox. o In oracle. 5 . Note that no results are displayed in the table.framework. and it lets you navigate more freely around your application with the menu present. At this point. simply make the required change and terminate your OC4J process. select the Go button to perform a blind query (this page does not comply with the coding standards that prohibit blind queries!).framework.server.apps.labsolutions.apps.DebugSearchCO. o In oracle.webui. webBean).DebugEmpSummar yVOImpl. • Add breakpoints to the following source code (use the instructions provided in the Hello. add a breakpoint inside the initQuery method at this line of code: DebugLabEmpSummaryVOImpl vo = getDebugLabEmpSummaryVO1().fnd.framework.labsolutions.
Since we know exactly what the source of the NullPointerException is. an OAMessageTextInputBean) is null. when using the JDeveloper packaged for Oracle Applications. you can simply glance at your code and figure out why the object you expected to be instantiated (in this case. Note that a standard OA Framework error page displays as shown in Figure 1. look for the text ## Detail 0 ## in the stack trace and read the exception data that immediately follows it.NullPointerException. This means you tried to invoke a method on a variable that has not been initialized.DebugSearchCO class. To access additional information about the error so you can debug it. select the here link. we can go right to the broken source code as shown in Figure 3 below. Figure 1: Example of an OA Framework Error Page This generic error page renders whenever an unexpected exception is thrown.webui.Task 2: Resolve a NullPointerException (NPE) In this task.lang. To find the nugget of information that you need to proceed. you need to create an exception breakpoint as shown in Task 4 below.fnd.apps. If you work with a stack trace that doesn't contain explicit line numbers.toolbox. most of the content is superfluous for your debugging purposes. debug information is compiled into the code so line numbers are provided in the stack trace.labsolutions.jsp in debug mode. For this particular error. you'll resolve one of the most common exceptions that you'll encounter: a java. Don't be daunted by the size of the stack trace. • Select the Debug Lab link when the test page renders. • Run test_fwklabsolutions. Figure 2: ## Detail 0 ## Stack Trace Information for a NullPointerException Tip: Fortunately. Figure 3: Source of the NullPointerException 6 . Instead.framework. Figure 2 shows that a NullPointerException was raised in the processRequest method at line 38 in the oracle. In most cases. we don't need to bother creating an exception breakpoint (you can always create one later if you need it). The OA Framework then displays the complete stack trace associated with the uncaught exception (a "stack trace" is a snapshot of the code execution path at the point where the exception is raised).
Proceed to Task 3 before testing your fix. see the corresponding Task 2 solution. If you need help so you can proceed. 7 .Try to figure out what is wrong with this code so you can fix it.
apps.labsolutions.framework. documentation and book suggestions: • Oracle Technology Network • JavaSoft Java Developer Connection To proceed: • Run test_fwklabsolutions. • Select the Debug Lab link when the test page renders.beans.apps.framework. please check the following for tutorials.jsp in debug mode. Figure 5: Source of the ClassCastException 8 . Figure 4: ## Detail 0 ## Stack Trace Information for a ClassCastException This tells us that we have a ClassCastException at line 37 in the processRequest method of the oracle. Try to figure out what is wrong with this code so you can fix it.ClassCastException.message.lang. Tip: If you're relatively new to Java and need additional information about class casting. Select the here link to access the stack trace. If you need help so you can proceed. Note that a standard OA Framework error page displays as shown in Figure 1 above. see the corresponding Task 3 solution. you'll resolve another common exception: a java. It also tells us that the class that we're incorrectly casting is oracle.fnd.OAMessageLovInputBean (this is the "message" part of the exception). This means you tried to perform an invalid cast from one object type to another. Figure 5 shows the code at line 37 that is causing the exception.DebugSearchCO class.webui.toolbox.Task 3: Resolve a ClassCastException In this task. and it's not working. and look for ## Detail 0 ## as shown in Figure 4 below. In other words.webui. we have an OAMessageLovInputBean that we're trying to cast to something else.fnd.
• Run test_fwklabsolutions. Tip: The generic OA Framework error page doesn't display in this case because the underlying exception is caught and "packaged" by BC4J as a user-friendly error message to be displayed at the top of the page. but it doesn't give you enough information about what you need to fix. • Right-click and select New Breakpoint. from the context menu.jsp in debug mode. • In the New Breakpoint window. For this. and you want to explore code state at the point where the exception is thrown).Task 4: Resolve a SQLStmtException In this task. however you can also add a breakpoint when you are not in debug mode by choosing View > Debug Windows > Breakpoints from the main menu). Note that query results are properly displayed. • Select the Debug Lab link when the test page renders.. • Enter the value "1" in the Employee Number field. 9 . Figure 6: SQLStmtException Displayed in an Error Message Box To create an exception breakpoint: • Place your cursor in the JDeveloper Breakpoints tab shown in Figure 7 below (note that this tab generally displays only when you run in debug mode. set the Breakpoint Type to Exception and set the Exception Class to the fully qualified name of the exception (in this case. This tells you that there is "something" wrong with the SQL statement you tried to execute. • Select the Go button to perform a blind query. you'll resolve a problem with the SQL statement that you try to execute when searching for employees.. The error message shown in Figure 6 displays at the top of your page. we need an exception breakpoint so we can dig a little deeper into the problem (exception breakpoints are essential if you need more information about the code that was executed before the exception is thrown. and select the Go button.
the exception is being thrown in the executeQuery method in the QueryCollection class. You'll see several other options that you might want to explore. It is particularly helpful if you want to access code that was executed before your breakpoint was reached. you can choose Export. and in the call stack (the Stack tab) as shown in Figure 9. you might read the following and decide that you want to add a breakpoint in the OAViewObjectImpl's executeQuery method so you can step through the code from this point until you reach the exception. Select OK to save your breakpoint. Tip: Try right-clicking on the class or method names in the call stack. For example. So. execution halts just before the highlighted line of code. simply double-click that line in the Stack window to open the corresponding source. Specifically.. To quickly access the executeQuery method. This is reflected in the source code above. Figure 8: Exception Breakpoint for SQLStmtException In this case. for example. select the Go button again (with your Employee Number search criteria).Figure 7: JDeveloper Breakpoints Tab • oracle. to save a copy of the call stack.SQLStmtException). To proceed.. it stops execution at the point where the exception is thrown as shown in Figure 8 below. Assuming JDeveloper has access to the source code.jbo. The call stack is a useful tool that reflects the code execution path in relation to the current breakpoint (it changes as you step through your code using the debugger). Figure 9: Call Stack State When the SQLStmtException is Thrown 10 .
we need to examine the exception state to see if it includes additional information that is not included in the message BC4J presents to the user. the exception includes the underlying ORA error. If you need help so you can proceed. instead of just knowing that we have a bad SQL statement. which is much more specific about the root cause of the problem. and this is invalid. we really don't need to navigate the call stack and add breakpoints at earlier processing points. Now. we know what to look for: our SQL statement includes the identifier EMPLOYEE_NUMBER. It's worth getting in the habit of looking at this quickly before bothering to debug the code since the problem may be obvious to you. you can often solve these problems by simply reading your SQL statement as shown in the original error message in Figure 6 above. Note: When you know your code well. 11 . Instead. At this level. Try to figure out what is wrong with this code so you can fix it. Figure 10 shows the Smart Data debugging window contents when the SQLStmtException breakpoint is reached.For this particular error. see the corresponding Task 4 solution.
AppsConnectionManager throws and handles an NPE). You can toggle this as needed. If you don't need additional information about how this exception is handled throughout the call stack.Figure 10: Smart Data Window Showing Code State Tip: When execution stops on the initial exception throw. You should simply select the Resume debugging option when you encounter these. right-click and select Disable Breakpoint. and you select the Resume debugging action. you'll notice that you encounter at least one in the course of normal page processing (for example. Select the breakpoint in the Breakpoints window. JDeveloper halts each time this exception is rethrown in the call stack. the first relevant NPE is likely to be in your code. Tip: When you create NullPointerException breakpoints. 12 . you can always disable the breakpoint after the initial exception is thrown to save yourself some time.
you might want to use a class method on your entity objects to examine its initialization and data access.server. To execute your class breakpoint: • In the LabSolutions project.Task 5: Use a Class Breakpoint In this task.toolbox. Tip: If you have problems with view object row initialization when creating new entity object based rows. • In the New Breakpoint window. you need to select oracle. • Select the Debug Lab link when the test page renders.. button next to the Class name field.schema. This is very useful when trying to learn how an unfamiliar class is used. run test_fwklabsolutions. Please proceed directly to Task 6. • When the Search page renders. but delete or disable your class breakpoint and select the Resume debugging option first.jsp in debug mode.. navigate through the packages and classes until you can select the target class (in this case. Note that you can also type your class name in directly without having to browse first.EmployeeEOImpl). and is more efficient than setting multiple breakpoints if you have heavy interaction with a given class and want to verify numerous method calls. from the context menu. 13 .framework. To create a class breakpoint: • Place your cursor in the JDeveloper Breakpoints tab. • Right-click and select New Breakpoint. You'll notice that JDeveloper halts execution every single time a method is called in EmployeeEOImpl and in any of its superclasses so you have a complete picture of how this object behaves (feel free to disable the class breakpoint before stepping through all the method calls!)..fnd. • Select OK to save your breakpoint. • In the Class Browser window.apps. select the Create button.. set the Breakpoint Type to Class and select the Browse. you'll use a class breakpoint to investigate all calls to a single class.
the first thing you should do is set a breakpoint on the corresponding "setter" (in this case.framework. it's often helpful to put a break point on another "setter" for a value that isn't having problems.schema. we'll investigate an unexpected validation failure in an entity object. you could: • Place your cursor in the JDeveloper Breakpoints tab.apps.toolbox. For example.setLastName • Select OK to save your breakpoint. While this can be very helpful in some situations.setLastName (any other setter in the entity object would work just as well) Tip: You could also define method breakpoints without opening the source code in your project. • Select the Create button again to return to the Create page. While you're in the entity object.framework.schema.EmployeeEOImpl.framework.EmployeeEOImpl.setPositio nCode • oracle. setPositionCode). Remember that the OA Framework steps through a data "post back" phase when an HTTP 14 .schema. Figure 11: PositionCode Validation Error Whenever entity object validation fails at the attribute level.fnd. and select the Apply button. the class breakpoint provides far more information than you need. • Enter all the required information for creating an employee (don't change the Position poplist value from President since the page isn't coded to let you enter the Manager value required for the other positions).apps. set the Breakpoint Type to Method and enter the fully qualified method name. if you're experiencing a failure at a specific point in your code.toolbox. Note that the attribute-level validation error shown in Figure 11 displays. For example: oracle. please add breakpoints to the following methods: • oracle.apps.Task 6: Investigate Unexpected Code Execution (Part 2) In the previous task. To proceed: • Select the Cancel button in the Create page to return to the Search page.. In this task..server. we used a class breakpoint for a fine-grained look at class usage. Given this.EmployeeEOImpl.fnd.toolbox.fnd. • Right-click and select New Breakpoint. from the context menu. • In the New Breakpoint window.server.server.
Tip: You might also want to add a breakpoint in the entity object's validateEntity method. If you add this breakpoint. Think about what might be wrong here so you can fix it. • Enter all the required information for creating an employee (don't change the Position poplist value from President since the page isn't coded to let you enter the Manager value required for the other positions). which in turn write data to the underlying entity object(s). all the entity object setters corresponding to the data you enter on the page should be called. You'll notice that the setPositionCode method is NOT being called -. Tip: When you've been debugging for a while. you often accumulate many breakpoints. When you're ready to move on. • Select the Create button again to return to the Create page. please see Implementing the View: Model Interaction in the OA Framework Developer's Guide. If you need help. For additional infromation about how and when data is read from and written to the server from the UI. All the data on the page is written to the underlying view object(s). you'll see when the entity-level validation is performed.even though a value is clearly selected in the poplist -. After calling all the setters in processFormData. Start with your page definition. see the corresponding Task 6 solution.while the setSalary method is being called correctly. To execute your breakpoints: • Select the Cancel button in the Create page to return to the Search page.POST request is issued (the OA Framework calls the processFormData method for all items in the web bean hierarchy). you might want to use the Breakpoints window context menus option Disable All or Remove All to quickly disable or delete your breakpoints. When you select the Apply submit button. the OA Framework valides each row in the view object that it "dirtied" by setting values. 15 . and select the Apply button. and consider what must be defined correctly for the position value to be written to the entity object attribute.
framework. The isAMStateNew() method in oracle.DebugBPageCO and add a breakpoint at the following line of code in processRequest(): Boolean isNew = pageContext. select the Resume debugging option so the page can render.2 Perform Test #1 • • • • In the LabSolutions project.DebugBLabAMImpl. the OA Framework will call this method just before it releases the application module.apps.fnd.OAPageContext is a convenient way for your controller code to see whether the application module state is new.toolbox.server. Tip: Remember that all application modules extend OAApplicationModuleImpl. After executing the code that sets the transaction "APageValue" value.OAApplicationModuleImpl is called just before an application module's state is reset.webui.labsolutions.Task 7: Explore Application Module Retention Behavior In this simple exercise you'll use the debugger to explore application module retention behavior while navigating between two pages. it is not accessible from the test_fwklabsolutions.framework.apps.toolbox.toolbox.fnd. this method will actually be called for the subclasses created for this lab: oracle. This will perform a JSP forward to the DebugBPG page with the retainAM request parameter set to true. see OA Framework State Management in the Developer's Guide.framework. Open oracle.server.fnd.apps. run the DebugAPG page in debug mode (you need to run this directly. Create a method breakpoint using the technique described above. The beforeRelease() method in oracle.apps. For additional information about this. Step 7. if you opt to release an application module instead of retaining it. so at runtime.fnd. aVal and bVal variables in the Data window.server. Step 7. When your first breakpoint is reached in DebugAPageCO.OAApplicationModuleImpl.server. select the Page B (Retain AM) submit button.framework.fnd. Note the state of the isNew.jsp). the application module was retained).framework. So. toggle the Data debugging window from the default Smart Data tab to the Data tab as shown in Figure 12 below.apps. or whether a cached application module with existing state was used for the page (in other words. When the page renders.apps.DebugALabAMImpl and oracle. Use the Step Over debugging option to execute each line of code in the processRequest method. The fully qualified method name to use is oracle.apps.beforeRelease.fnd.isAMStateNew().framework.toolbox.framework.1 Create Breakpoints • • • Open oracle.webui.labsolutions.labsolutions.isAMStateNew().DebugAPageCO and add a breakpoint at the following line of code in processRequest: boolean isNew = pageContext. Figure 12: Data Window State When DebugAPG Initially Renders 16 .labsolutions.webui.fnd.
and note that you again enter the beforeRelease method for DebugALabAMImpl. if you look at the "this" pointer in the Data window (for those who are new to Java. "this" iterally means "this object" -. this time select the Page B submit button. This will perform a JSP forward back to the DebugAPG page with the retainAM request parameter set to true. Since we retained the AM when navigating to this page (check the processFormRequest method in DebugAPageCO for confirmation). Test 1 solution if you need help. When you set the retainAM request parameter to false. why is it null? See the Task 7. bVal and aVal variables. However. Note: do not stop running or make any changes to the code at this point. 17 . Again. Test 1 solution if you need help. wouldn't you expect this value to be false? Why might it be true? Also.• • • • • • When you reach the DebugBPageCO processRequest breakpoint. JDeveloper will halt execution at the beforeRelease method in the OAApplicationModuleImpl source. Can you explain this? See the Task 7. select the Debug A (Retain AM) submit button. You'll notice that the isNew value is set to true. Select the Resume debugging option. When DebugAPG renders. meaning that the application module state for this page is new. At this point.a reference to the current object). if we saved the aVal value on the transaction. use the debugger to step through the processRequest code and check the state of the isNew. ALL root UI application modules that are currently cached (retained) are released. carefully execute each line of code and note the state of the isNew. and aVal = "A". you'll see that the object type is actually DebugBLabAMImpl. aVal and bVal variables. When the DebugBPageCO renders. You'll notice that isNew = false. This will perform a JSP forward back to the DebugBPG page with the retainAM request parameter set to false.
If you were wrong. and you're not sure why.Figure 13: Data Window State When beforeRelease Breakpoint is Reached Step 7. This opens a Modify Value window with the Current Value set to the objec'ts memory address. • Run DebugAPG in debug mode. Test 2. Your cached DebugALabAM and its state remains intact.toolbox. the code performs a JSP forward to the DebugBPG while retaining the application module. Figure 14: DebugLabAMImpl Object's Memory Address • 18 . and when the page renders. aVal and bVal variable values to be? Step through the code and see if you were right. select the Debug B Page (Retain AM) submit button. Step through the processRequest code noting the variable states.labsolutions. • Before you debug the processRequest method in DebugBPG. Another way to verify whether pages are using the same instance of the same application module type is to check the object's memory address (it's internal unique identifier). double-click the "this" Name or Type value in the Data window (shown in Figure 13 above).DebugALabAMImpl. see the Task 7. Tip: In this test.fnd. • Try navigating back and forth between the pages using the buttons with the "Retain AM" label. Again.server. To do this.3 Perform Test #2 Terminate the current OC4J process and change the AM Definition property of PageLayoutRN region in DebugBPG to oracle.framework. both pages are using the same application module instance. what do you expect the isNew.apps.
lang.lang.toolbox. and if you experience problems related to Numbers in your code. and you'll get a runtime error when you try to set the value.apps. Just try to remember to always import oracle. but it walks you through a common mistake that can be difficult to understand if you've not seen anything like this before.Number when you need it. In this particular code example.lang classes are automatically included.domain.domain. 19 .domain.framework. which is why you don't have to explicitly import commonly used classes like String).Number.28): class java.Task 8: Resolve a Common Missing Import This task doesn't involve the use of the debugger. we are attempting to instantiate a Number class so we're getting the error shown above.Number class (the java.Number import. always remember to check your imports before spending a lot of additional time debugging this.Number is abstract. If you fail to do this. notice that you get the following compilation error: Error(34.jbo.server. • Rebuild the LabSolutions project. Alternatively. • Open oracle.labsolutions.DebugLabEmpFullVOImpl and comment out the oracle. you must remember to import oracle. cannot be instantiated Whenever you use a Number in an OA Framework application.fnd.jbo. you might define a Number member variable without explicitly instantiating it. the compiler assumes that this is a java.jbo.
see the JDeveloper OA Component Properties documentation for a description of each property by region and item type. 20 . Figure 15: Unwanted Header Line Above the Employee Number Field Congratulations! You are now finished with this lab. it's more likely to be caused by an incorrect property setting. Do you know why this line is rendering? Do you know how to stop it? See the Task 9 solution if you need help.is sometimes the smallest oversight on your part leads to an unexpected result. If you're uncertain about how various property settings affect the corresponding HTML. the only thing you can really do in this case is carefully inspect all the property settings for the regions and/or items related to the undesirable HTML. debugging won't help you solve a problem because nothing's actually wrong with the code. The downside of working with a "black box" that does a lot of the work for you -particularly when you "code" declaratively -.Task 9: Investigate Unexpected UI Results Sometimes. Also see the various UI implementation topics in Chapter 4 of the OA Framework Developer's Guide. For example. Although a bit tedious. While something like this might be a bug. you might have noticed that a header line is rendering above the Employee Number field in the debug lab Create page (see Figure 15).
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.