Buggy code:
public class PrintDialog extends Dialog { PrinterData printerData = new PrinterData ( ) ; public PrintDialog ( Shell parent ) { } public PrintDialog ( Shell parent , int style ) { } public void setPrinterData ( PrinterData data ) { } public PrinterData getPrinterData ( ) { } public PrinterData open ( ) { int [ ] buffer = new int [ 1 ] ; if ( ( OS . PMCreateSession ( buffer ) ) == ( OS . noErr ) ) { int printSession = buffer [ 0 ] ; if ( ( OS . PMCreatePrintSettings ( buffer ) ) == ( OS . noErr ) ) { int printSettings = buffer [ 0 ] ; OS . PMSessionDefaultPrintSettings ( printSession , printSettings ) ; if ( ( OS . PMCreatePageFormat ( buffer ) ) == ( OS . noErr ) ) { int pageFormat = buffer [ 0 ] ; OS . PMSessionDefaultPageFormat ( printSession , pageFormat ) ; OS . PMSessionSetDestination ( printSession , printSettings , ( ( short ) ( printerData . printToFile ? OS . kPMDestinationFile : OS . kPMDestinationPrinter ) ) , 0 , 0 ) ; if ( ( printerData . scope ) == ( PrinterData . PAGE_RANGE ) ) { OS . PMSetFirstPage ( printSettings , printerData . startPage , false ) ; OS . PMSetLastPage ( printSettings , printerData . endPage , false ) ; OS . PMSetPageRange ( printSettings , printerData . startPage , printerData . endPage ) ; } else { OS . PMSetPageRange ( printSettings , 1 , kPMPrintAllPages ) ; } OS . PMSetCopies ( printSettings , printerData . copyCount , false ) ; OS . PMSetCollate ( printSettings , printerData . collate ) ; <START_BUG> OS . PMSetOrientation ( pageFormat , ( ( short ) ( ( printerData . orientation ) == ( PrinterData . LANDSCAPE ) ? OS . kPMLandscape : OS . kPMPortrait ) ) , false ) ; <END_BUG> boolean [ ] accepted = new boolean [ 1 ] ; if ( ( OS . VERSION ) >= 4176 ) { int printDialogOptions = ( OS . kPMShowDefaultInlineItems ) | ( OS . kPMShowPageAttributesPDE ) ; OS . PMShowPrintDialogWithOptions ( printSession , printSettings , pageFormat , printDialogOptions , accepted ) ; } else { OS . PMSessionPageSetupDialog ( printSession , pageFormat , accepted ) ; if ( accepted [ 0 ] ) OS . PMSessionPrintDialog ( printSession , printSettings , pageFormat , accepted ) ; } if ( accepted [ 0 ] ) { short [ ] destType = new short [ 1 ] ; OS . PMSessionGetDestinationType ( printSession , printSettings , destType ) ; String name = Printer . getCurrentPrinterName ( printSession ) ; String driver = Printer . DRIVER ; switch ( destType [ 0 ] ) { case OS . kPMDestinationFax : driver = Printer . FAX_DRIVER ; break ; case OS . kPMDestinationFile : driver = Printer . FILE_DRIVER ; break ; case OS . kPMDestinationPreview : driver = Printer . PREVIEW_DRIVER ; break ; case OS . kPMDestinationPrinter : driver = Printer . PRINTER_DRIVER ; break ; } PrinterData data = new PrinterData ( driver , name ) ; if ( ( destType [ 0 ] ) == ( OS . kPMDestinationFile ) ) { data . printToFile = true ; OS . PMSessionCopyDestinationLocation ( printSession , printSettings , buffer ) ; int fileName = OS . CFURLCopyFileSystemPath ( buffer [ 0 ] , kCFURLPOSIXPathStyle ) ; OS . CFRelease ( buffer [ 0 ] ) ; data . fileName = Printer . getString ( fileName ) ; OS . CFRelease ( fileName ) ; } OS . PMGetCopies ( printSettings , buffer ) ; data . copyCount = buffer [ 0 ] ; OS . PMGetFirstPage ( printSettings , buffer ) ; data . startPage = buffer [ 0 ] ; OS . PMGetLastPage ( printSettings , buffer ) ; data . endPage = buffer [ 0 ] ; if ( ( ( data . startPage ) == 1 ) && ( ( data . endPage ) == ( OS . kPMPrintAllPages ) ) ) { data . scope = PrinterData . ALL_PAGES ; } else { data . scope = PrinterData . PAGE_RANGE ; } boolean [ ] collate = new boolean [ 1 ] ; OS . PMGetCollate ( printSettings , collate ) ; data . collate = collate [ 0 ] ; short [ ] orientation = new short [ 1 ] ; OS . PMGetOrientation ( pageFormat , orientation ) ; data . orientation = ( ( orientation [ 0 ] ) == ( OS . kPMLandscape ) ) ? PrinterData . LANDSCAPE : PrinterData . PORTRAIT ; int [ ] flatSettings = new int [ 1 ] ; OS . PMFlattenPrintSettings ( printSettings , flatSettings ) ; int [ ] flatFormat = new int [ 1 ] ; OS . PMFlattenPageFormat ( pageFormat , flatFormat ) ; int settingsLength = OS . GetHandleSize ( flatSettings [ 0 ] ) ; int formatLength = OS . GetHandleSize ( flatFormat [ 0 ] ) ; byte [ ] otherData = data . otherData = new byte [ ( settingsLength + formatLength ) + 8 ] ; int offset = 0 ; offset = Printer . packData ( flatSettings [ 0 ] , otherData , offset ) ; offset = Printer . packData ( flatFormat [ 0 ] , otherData , offset ) ; OS . DisposeHandle ( flatSettings [ 0 ] ) ; OS . DisposeHandle ( flatFormat [ 0 ] ) ; printerData = data ; return data ; } OS . PMRelease ( pageFormat ) ; } OS . PMRelease ( printSettings ) ; } OS . PMRelease ( printSession ) ; } return null ; } public int getScope ( ) { } public void setScope ( int scope ) { } public int getStartPage ( ) { } public void setStartPage ( int startPage ) { }

Fix:
OS . PMSetOrientation ( pageFormat , ( ( printerData . orientation ) == ( PrinterData . LANDSCAPE ) ? OS . kPMLandscape : OS . kPMPortrait ) , false ) ;