1.1 --- a/make/com/sun/servicetag/Makefile Thu Sep 15 18:53:28 2011 -0700
1.2 +++ b/make/com/sun/servicetag/Makefile Mon Sep 19 19:40:59 2011 -0700
1.3 @@ -47,7 +47,7 @@
1.4 # Add all properties files to the FILES_copy list
1.5 SWORDFISH_properties := $(shell \
1.6 $(CD) $(SHARE_SRC)/classes/com/sun/servicetag/resources; \
1.7 - $(FIND) . -name 'javase_*_swordfish.properties' -print ; \
1.8 + $(FIND) . -name 'javase_*.properties' -print ; \
1.9 )
1.10 FILES_copy += $(shell \
1.11 for f in $(SWORDFISH_properties) ; do \
2.1 --- a/make/jprt.properties Thu Sep 15 18:53:28 2011 -0700
2.2 +++ b/make/jprt.properties Mon Sep 19 19:40:59 2011 -0700
2.3 @@ -258,6 +258,15 @@
2.4 windows_i586_5.1-product-c1-jdk_security3, \
2.5 windows_x64_5.2-product-c2-jdk_security3, \
2.6 \
2.7 + solaris_sparc_5.10-product-c1-jdk_sound, \
2.8 + solaris_sparcv9_5.10-product-c2-jdk_sound, \
2.9 + solaris_i586_5.10-product-c1-jdk_sound, \
2.10 + solaris_x64_5.10-product-c2-jdk_sound, \
2.11 + linux_i586_2.6-product-{c1|c2}-jdk_sound, \
2.12 + linux_x64_2.6-product-c2-jdk_sound, \
2.13 + windows_i586_5.1-product-c1-jdk_sound, \
2.14 + windows_x64_5.2-product-c2-jdk_sound, \
2.15 + \
2.16 solaris_sparc_5.10-product-c1-jdk_swing, \
2.17 solaris_sparcv9_5.10-product-c2-jdk_swing, \
2.18 solaris_i586_5.10-product-c1-jdk_swing, \
3.1 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java Thu Sep 15 18:53:28 2011 -0700
3.2 +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java Mon Sep 19 19:40:59 2011 -0700
3.3 @@ -763,7 +763,7 @@
3.4 }
3.5 } catch (IllegalThumbException e) {
3.6 // Should never happen
3.7 - throw new InternalError("Illegal thumb in setThumbnail!");
3.8 + throw new InternalError("Illegal thumb in setThumbnail!", e);
3.9 }
3.10 }
3.11
4.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java Thu Sep 15 18:53:28 2011 -0700
4.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java Mon Sep 19 19:40:59 2011 -0700
4.3 @@ -529,21 +529,25 @@
4.4 Locale l = fc.getLocale();
4.5
4.6 enterFolderNameLabelText = UIManager.getString("FileChooser.enterFolderNameLabelText",l);
4.7 - enterFolderNameLabelMnemonic = UIManager.getInt("FileChooser.enterFolderNameLabelMnemonic");
4.8 + enterFolderNameLabelMnemonic = getMnemonic("FileChooser.enterFolderNameLabelMnemonic", l);
4.9 enterFileNameLabelText = UIManager.getString("FileChooser.enterFileNameLabelText",l);
4.10 - enterFileNameLabelMnemonic = UIManager.getInt("FileChooser.enterFileNameLabelMnemonic");
4.11 + enterFileNameLabelMnemonic = getMnemonic("FileChooser.enterFileNameLabelMnemonic", l);
4.12
4.13 filesLabelText = UIManager.getString("FileChooser.filesLabelText",l);
4.14 - filesLabelMnemonic = UIManager.getInt("FileChooser.filesLabelMnemonic");
4.15 + filesLabelMnemonic = getMnemonic("FileChooser.filesLabelMnemonic", l);
4.16
4.17 foldersLabelText = UIManager.getString("FileChooser.foldersLabelText",l);
4.18 - foldersLabelMnemonic = UIManager.getInt("FileChooser.foldersLabelMnemonic");
4.19 + foldersLabelMnemonic = getMnemonic("FileChooser.foldersLabelMnemonic", l);
4.20
4.21 pathLabelText = UIManager.getString("FileChooser.pathLabelText",l);
4.22 - pathLabelMnemonic = UIManager.getInt("FileChooser.pathLabelMnemonic");
4.23 + pathLabelMnemonic = getMnemonic("FileChooser.pathLabelMnemonic", l);
4.24
4.25 filterLabelText = UIManager.getString("FileChooser.filterLabelText",l);
4.26 - filterLabelMnemonic = UIManager.getInt("FileChooser.filterLabelMnemonic");
4.27 + filterLabelMnemonic = getMnemonic("FileChooser.filterLabelMnemonic", l);
4.28 + }
4.29 +
4.30 + private Integer getMnemonic(String key, Locale l) {
4.31 + return SwingUtilities2.getUIDefaultsInt(key, l);
4.32 }
4.33
4.34 protected void installIcons(JFileChooser fc) {
5.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/MotifLookAndFeel.java Thu Sep 15 18:53:28 2011 -0700
5.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/MotifLookAndFeel.java Mon Sep 19 19:40:59 2011 -0700
5.3 @@ -1215,11 +1215,6 @@
5.4 "EditorPane.focusInputMap", multilineInputMap,
5.5
5.6
5.7 - "FileChooser.pathLabelMnemonic", new Integer(KeyEvent.VK_P), // 'p'
5.8 - "FileChooser.filterLabelMnemonic", new Integer (KeyEvent.VK_R), // 'r'
5.9 - "FileChooser.foldersLabelMnemonic", new Integer (KeyEvent.VK_L), // 'l'
5.10 - "FileChooser.filesLabelMnemonic", new Integer (KeyEvent.VK_I), // 'i'
5.11 - "FileChooser.enterFileNameLabelMnemonic", new Integer (KeyEvent.VK_N), // 'n'
5.12 "FileChooser.ancestorInputMap",
5.13 new UIDefaults.LazyInputMap(new Object[] {
5.14 "ESCAPE", "cancelSelection"
6.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif.properties Thu Sep 15 18:53:28 2011 -0700
6.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif.properties Mon Sep 19 19:40:59 2011 -0700
6.3 @@ -27,10 +27,15 @@
6.4 FileChooser.updateButtonText=Update
6.5 FileChooser.helpButtonText=Help
6.6 FileChooser.pathLabelText=Enter path or folder name:
6.7 +FileChooser.pathLabelMnemonic=80
6.8 FileChooser.filterLabelText=Filter
6.9 +FileChooser.filterLabelMnemonic=82
6.10 FileChooser.foldersLabelText=Folders
6.11 +FileChooser.foldersLabelMnemonic=76
6.12 FileChooser.filesLabelText=Files
6.13 +FileChooser.filesLabelMnemonic=73
6.14 FileChooser.enterFileNameLabelText=Enter file name:
6.15 +FileChooser.enterFileNameLabelMnemonic=78
6.16 FileChooser.enterFolderNameLabelText=Enter folder name:
6.17
6.18 FileChooser.cancelButtonToolTipText=Abort file chooser dialog.
7.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_de.properties Thu Sep 15 18:53:28 2011 -0700
7.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_de.properties Mon Sep 19 19:40:59 2011 -0700
7.3 @@ -27,10 +27,15 @@
7.4 FileChooser.updateButtonText=Aktualisieren
7.5 FileChooser.helpButtonText=Hilfe
7.6 FileChooser.pathLabelText=Pfad- oder Ordnernamen eingeben:
7.7 +FileChooser.pathLabelMnemonic=80
7.8 FileChooser.filterLabelText=Filter
7.9 +FileChooser.filterLabelMnemonic=82
7.10 FileChooser.foldersLabelText=Ordner
7.11 +FileChooser.foldersLabelMnemonic=76
7.12 FileChooser.filesLabelText=Dateien
7.13 +FileChooser.filesLabelMnemonic=73
7.14 FileChooser.enterFileNameLabelText=Dateinamen eingeben:
7.15 +FileChooser.enterFileNameLabelMnemonic=78
7.16 FileChooser.enterFolderNameLabelText=Ordnernamen eingeben:
7.17
7.18 FileChooser.cancelButtonToolTipText=Dialogfeld f\u00FCr Dateiauswahl schlie\u00DFen.
8.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_es.properties Thu Sep 15 18:53:28 2011 -0700
8.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_es.properties Mon Sep 19 19:40:59 2011 -0700
8.3 @@ -27,10 +27,15 @@
8.4 FileChooser.updateButtonText=Actualizar
8.5 FileChooser.helpButtonText=Ayuda
8.6 FileChooser.pathLabelText=Introducir nombre de la ruta de acceso o carpeta:
8.7 +FileChooser.pathLabelMnemonic=80
8.8 FileChooser.filterLabelText=Filtro
8.9 +FileChooser.filterLabelMnemonic=82
8.10 FileChooser.foldersLabelText=Carpetas
8.11 +FileChooser.foldersLabelMnemonic=76
8.12 FileChooser.filesLabelText=Archivos
8.13 +FileChooser.filesLabelMnemonic=73
8.14 FileChooser.enterFileNameLabelText=Introducir nombre de archivo:
8.15 +FileChooser.enterFileNameLabelMnemonic=78
8.16 FileChooser.enterFolderNameLabelText=Introducir nombre de carpeta:
8.17
8.18 FileChooser.cancelButtonToolTipText=Abortar cuadro de di\u00E1logo del selector de archivos.
9.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_fr.properties Thu Sep 15 18:53:28 2011 -0700
9.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_fr.properties Mon Sep 19 19:40:59 2011 -0700
9.3 @@ -27,10 +27,15 @@
9.4 FileChooser.updateButtonText=Mettre \u00E0 jour
9.5 FileChooser.helpButtonText=Aide
9.6 FileChooser.pathLabelText=Entrez le chemin ou le nom du dossier :
9.7 +FileChooser.pathLabelMnemonic=80
9.8 FileChooser.filterLabelText=Filtre
9.9 +FileChooser.filterLabelMnemonic=82
9.10 FileChooser.foldersLabelText=Dossiers
9.11 +FileChooser.foldersLabelMnemonic=76
9.12 FileChooser.filesLabelText=Fichiers
9.13 +FileChooser.filesLabelMnemonic=73
9.14 FileChooser.enterFileNameLabelText=Entrez le nom du fichier :
9.15 +FileChooser.enterFileNameLabelMnemonic=78
9.16 FileChooser.enterFolderNameLabelText=Entrez le nom du dossier :
9.17
9.18 FileChooser.cancelButtonToolTipText=Ferme la bo\u00EEte de dialogue du s\u00E9lecteur de fichiers.
10.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_it.properties Thu Sep 15 18:53:28 2011 -0700
10.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_it.properties Mon Sep 19 19:40:59 2011 -0700
10.3 @@ -27,10 +27,15 @@
10.4 FileChooser.updateButtonText=Aggiorna
10.5 FileChooser.helpButtonText=?
10.6 FileChooser.pathLabelText=Percorso o nome cartella:
10.7 +FileChooser.pathLabelMnemonic=80
10.8 FileChooser.filterLabelText=Filtro
10.9 +FileChooser.filterLabelMnemonic=82
10.10 FileChooser.foldersLabelText=Cartelle
10.11 +FileChooser.foldersLabelMnemonic=76
10.12 FileChooser.filesLabelText=File
10.13 +FileChooser.filesLabelMnemonic=73
10.14 FileChooser.enterFileNameLabelText=Nome file:
10.15 +FileChooser.enterFileNameLabelMnemonic=78
10.16 FileChooser.enterFolderNameLabelText=Nome cartella:
10.17
10.18 FileChooser.cancelButtonToolTipText=Chiude la finestra di dialogo di selezione file.
11.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_ja.properties Thu Sep 15 18:53:28 2011 -0700
11.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_ja.properties Mon Sep 19 19:40:59 2011 -0700
11.3 @@ -27,10 +27,15 @@
11.4 FileChooser.updateButtonText=\u66F4\u65B0
11.5 FileChooser.helpButtonText=\u30D8\u30EB\u30D7
11.6 FileChooser.pathLabelText=\u30D1\u30B9\u307E\u305F\u306F\u30D5\u30A9\u30EB\u30C0\u540D\u3092\u5165\u529B:
11.7 +FileChooser.pathLabelMnemonic=80
11.8 FileChooser.filterLabelText=\u30D5\u30A3\u30EB\u30BF
11.9 +FileChooser.filterLabelMnemonic=82
11.10 FileChooser.foldersLabelText=\u30D5\u30A9\u30EB\u30C0
11.11 +FileChooser.foldersLabelMnemonic=76
11.12 FileChooser.filesLabelText=\u30D5\u30A1\u30A4\u30EB
11.13 +FileChooser.filesLabelMnemonic=73
11.14 FileChooser.enterFileNameLabelText=\u30D5\u30A1\u30A4\u30EB\u540D\u3092\u5165\u529B:
11.15 +FileChooser.enterFileNameLabelMnemonic=78
11.16 FileChooser.enterFolderNameLabelText=\u30D5\u30A9\u30EB\u30C0\u540D\u3092\u5165\u529B:
11.17
11.18 FileChooser.cancelButtonToolTipText=\u30D5\u30A1\u30A4\u30EB\u30FB\u30C1\u30E5\u30FC\u30B6\u30FB\u30C0\u30A4\u30A2\u30ED\u30B0\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002
12.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_ko.properties Thu Sep 15 18:53:28 2011 -0700
12.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_ko.properties Mon Sep 19 19:40:59 2011 -0700
12.3 @@ -27,10 +27,15 @@
12.4 FileChooser.updateButtonText=\uAC31\uC2E0
12.5 FileChooser.helpButtonText=\uB3C4\uC6C0\uB9D0
12.6 FileChooser.pathLabelText=\uACBD\uB85C \uB610\uB294 \uD3F4\uB354 \uC774\uB984 \uC785\uB825:
12.7 +FileChooser.pathLabelMnemonic=80
12.8 FileChooser.filterLabelText=\uD544\uD130
12.9 +FileChooser.filterLabelMnemonic=82
12.10 FileChooser.foldersLabelText=\uD3F4\uB354
12.11 +FileChooser.foldersLabelMnemonic=76
12.12 FileChooser.filesLabelText=\uD30C\uC77C
12.13 +FileChooser.filesLabelMnemonic=73
12.14 FileChooser.enterFileNameLabelText=\uD30C\uC77C \uC774\uB984 \uC785\uB825:
12.15 +FileChooser.enterFileNameLabelMnemonic=78
12.16 FileChooser.enterFolderNameLabelText=\uD3F4\uB354 \uC774\uB984 \uC785\uB825:
12.17
12.18 FileChooser.cancelButtonToolTipText=\uD30C\uC77C \uC120\uD0DD\uAE30 \uB300\uD654\uC0C1\uC790\uB97C \uC911\uB2E8\uD569\uB2C8\uB2E4.
13.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_pt_BR.properties Thu Sep 15 18:53:28 2011 -0700
13.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_pt_BR.properties Mon Sep 19 19:40:59 2011 -0700
13.3 @@ -27,10 +27,15 @@
13.4 FileChooser.updateButtonText=Atualizar
13.5 FileChooser.helpButtonText=Ajuda
13.6 FileChooser.pathLabelText=Informar caminho ou nome da pasta:
13.7 +FileChooser.pathLabelMnemonic=80
13.8 FileChooser.filterLabelText=Filtro
13.9 +FileChooser.filterLabelMnemonic=82
13.10 FileChooser.foldersLabelText=Pastas
13.11 +FileChooser.foldersLabelMnemonic=76
13.12 FileChooser.filesLabelText=Arquivos
13.13 +FileChooser.filesLabelMnemonic=73
13.14 FileChooser.enterFileNameLabelText=Informar nome do arquivo:
13.15 +FileChooser.enterFileNameLabelMnemonic=78
13.16 FileChooser.enterFolderNameLabelText=Informar nome da pasta:
13.17
13.18 FileChooser.cancelButtonToolTipText=Abortar caixa de di\u00E1logo do seletor de arquivos.
14.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_sv.properties Thu Sep 15 18:53:28 2011 -0700
14.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_sv.properties Mon Sep 19 19:40:59 2011 -0700
14.3 @@ -27,10 +27,15 @@
14.4 FileChooser.updateButtonText=Uppdatera
14.5 FileChooser.helpButtonText=Hj\u00E4lp
14.6 FileChooser.pathLabelText=Ange s\u00F6kv\u00E4g eller mappnamn:
14.7 +FileChooser.pathLabelMnemonic=80
14.8 FileChooser.filterLabelText=Filter
14.9 +FileChooser.filterLabelMnemonic=82
14.10 FileChooser.foldersLabelText=Mappar
14.11 +FileChooser.foldersLabelMnemonic=76
14.12 FileChooser.filesLabelText=Filer
14.13 +FileChooser.filesLabelMnemonic=73
14.14 FileChooser.enterFileNameLabelText=Ange filnamn:
14.15 +FileChooser.enterFileNameLabelMnemonic=78
14.16 FileChooser.enterFolderNameLabelText=Ange ett mappnamn:
14.17
14.18 FileChooser.cancelButtonToolTipText=Avbryt dialogrutan Filv\u00E4ljare.
15.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_zh_CN.properties Thu Sep 15 18:53:28 2011 -0700
15.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_zh_CN.properties Mon Sep 19 19:40:59 2011 -0700
15.3 @@ -27,10 +27,15 @@
15.4 FileChooser.updateButtonText=\u66F4\u65B0
15.5 FileChooser.helpButtonText=\u5E2E\u52A9
15.6 FileChooser.pathLabelText=\u952E\u5165\u8DEF\u5F84\u6216\u6587\u4EF6\u5939\u540D:
15.7 +FileChooser.pathLabelMnemonic=80
15.8 FileChooser.filterLabelText=\u7B5B\u9009\u5668
15.9 +FileChooser.filterLabelMnemonic=82
15.10 FileChooser.foldersLabelText=\u6587\u4EF6\u5939
15.11 +FileChooser.foldersLabelMnemonic=76
15.12 FileChooser.filesLabelText=\u6587\u4EF6
15.13 +FileChooser.filesLabelMnemonic=73
15.14 FileChooser.enterFileNameLabelText=\u952E\u5165\u6587\u4EF6\u540D:
15.15 +FileChooser.enterFileNameLabelMnemonic=78
15.16 FileChooser.enterFolderNameLabelText=\u8F93\u5165\u6587\u4EF6\u5939\u540D:
15.17
15.18 FileChooser.cancelButtonToolTipText=\u4E2D\u6B62\u6587\u4EF6\u9009\u62E9\u5668\u5BF9\u8BDD\u6846\u3002
16.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_zh_TW.properties Thu Sep 15 18:53:28 2011 -0700
16.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/resources/motif_zh_TW.properties Mon Sep 19 19:40:59 2011 -0700
16.3 @@ -27,10 +27,15 @@
16.4 FileChooser.updateButtonText=\u66F4\u65B0
16.5 FileChooser.helpButtonText=\u8AAA\u660E
16.6 FileChooser.pathLabelText=\u8F38\u5165\u8DEF\u5F91\u6216\u8CC7\u6599\u593E\u540D\u7A31:
16.7 +FileChooser.pathLabelMnemonic=80
16.8 FileChooser.filterLabelText=\u7BE9\u9078
16.9 +FileChooser.filterLabelMnemonic=82
16.10 FileChooser.foldersLabelText=\u8CC7\u6599\u593E
16.11 +FileChooser.foldersLabelMnemonic=76
16.12 FileChooser.filesLabelText=\u6A94\u6848
16.13 +FileChooser.filesLabelMnemonic=73
16.14 FileChooser.enterFileNameLabelText=\u8F38\u5165\u6A94\u6848\u540D\u7A31:
16.15 +FileChooser.enterFileNameLabelMnemonic=78
16.16 FileChooser.enterFolderNameLabelText=\u8F38\u5165\u8CC7\u6599\u593E\u540D\u7A31:
16.17
16.18 FileChooser.cancelButtonToolTipText=\u4E2D\u6B62\u6A94\u6848\u9078\u64C7\u5668\u5C0D\u8A71\u65B9\u584A\u3002
17.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java Thu Sep 15 18:53:28 2011 -0700
17.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java Mon Sep 19 19:40:59 2011 -0700
17.3 @@ -528,16 +528,16 @@
17.4
17.5 Locale l = fc.getLocale();
17.6
17.7 - lookInLabelMnemonic = UIManager.getInt("FileChooser.lookInLabelMnemonic");
17.8 + lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
17.9 lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
17.10 saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
17.11
17.12 - fileNameLabelMnemonic = UIManager.getInt("FileChooser.fileNameLabelMnemonic");
17.13 + fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
17.14 fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
17.15 - folderNameLabelMnemonic = UIManager.getInt("FileChooser.folderNameLabelMnemonic");
17.16 + folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
17.17 folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l);
17.18
17.19 - filesOfTypeLabelMnemonic = UIManager.getInt("FileChooser.filesOfTypeLabelMnemonic");
17.20 + filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
17.21 filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
17.22
17.23 upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l);
17.24 @@ -550,6 +550,10 @@
17.25 viewMenuButtonAccessibleName = UIManager.getString("FileChooser.viewMenuButtonAccessibleName",l);
17.26 }
17.27
17.28 + private Integer getMnemonic(String key, Locale l) {
17.29 + return SwingUtilities2.getUIDefaultsInt(key, l);
17.30 + }
17.31 +
17.32 protected void installListeners(JFileChooser fc) {
17.33 super.installListeners(fc);
17.34 ActionMap actionMap = getActionMap();
18.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Thu Sep 15 18:53:28 2011 -0700
18.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Mon Sep 19 19:40:59 2011 -0700
18.3 @@ -770,9 +770,6 @@
18.4 "icons/NewFolder.gif"),
18.5 "FileChooser.useSystemExtensionHiding", Boolean.TRUE,
18.6
18.7 - "FileChooser.lookInLabelMnemonic", Integer.valueOf(KeyEvent.VK_I),
18.8 - "FileChooser.fileNameLabelMnemonic", Integer.valueOf(KeyEvent.VK_N),
18.9 - "FileChooser.filesOfTypeLabelMnemonic", Integer.valueOf(KeyEvent.VK_T),
18.10 "FileChooser.usesSingleFilePane", Boolean.TRUE,
18.11 "FileChooser.noPlacesBar", new DesktopProperty("win.comdlg.noPlacesBar",
18.12 Boolean.FALSE),
19.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows.properties Thu Sep 15 18:53:28 2011 -0700
19.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows.properties Mon Sep 19 19:40:59 2011 -0700
19.3 @@ -19,10 +19,14 @@
19.4 ############ FILE CHOOSER STRINGS #############
19.5
19.6 FileChooser.lookInLabelText=Look in:
19.7 +FileChooser.lookInLabelMnemonic=73
19.8 FileChooser.saveInLabelText=Save in:
19.9 FileChooser.fileNameLabelText=File name:
19.10 +FileChooser.fileNameLabelMnemonic=78
19.11 FileChooser.folderNameLabelText=Folder name:
19.12 +FileChooser.folderNameLabelMnemonic=78
19.13 FileChooser.filesOfTypeLabelText=Files of type:
19.14 +FileChooser.filesOfTypeLabelMnemonic=84
19.15 FileChooser.upFolderToolTipText=Up One Level
19.16 FileChooser.upFolderAccessibleName=Up
19.17 FileChooser.homeFolderToolTipText=Home
20.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_de.properties Thu Sep 15 18:53:28 2011 -0700
20.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_de.properties Mon Sep 19 19:40:59 2011 -0700
20.3 @@ -19,10 +19,14 @@
20.4 ############ FILE CHOOSER STRINGS #############
20.5
20.6 FileChooser.lookInLabelText=Suchen in:
20.7 +FileChooser.lookInLabelMnemonic=73
20.8 FileChooser.saveInLabelText=Speichern in:
20.9 FileChooser.fileNameLabelText=Dateiname:
20.10 +FileChooser.fileNameLabelMnemonic=78
20.11 FileChooser.folderNameLabelText=Ordnername:
20.12 +FileChooser.folderNameLabelMnemonic=78
20.13 FileChooser.filesOfTypeLabelText=Dateityp:
20.14 +FileChooser.filesOfTypeLabelMnemonic=84
20.15 FileChooser.upFolderToolTipText=Eine Ebene h\u00F6her
20.16 FileChooser.upFolderAccessibleName=Nach oben
20.17 FileChooser.homeFolderToolTipText=Home
21.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_es.properties Thu Sep 15 18:53:28 2011 -0700
21.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_es.properties Mon Sep 19 19:40:59 2011 -0700
21.3 @@ -19,10 +19,14 @@
21.4 ############ FILE CHOOSER STRINGS #############
21.5
21.6 FileChooser.lookInLabelText=Buscar en:
21.7 +FileChooser.lookInLabelMnemonic=73
21.8 FileChooser.saveInLabelText=Guardar en:
21.9 FileChooser.fileNameLabelText=Nombre de Archivo:
21.10 +FileChooser.fileNameLabelMnemonic=78
21.11 FileChooser.folderNameLabelText=Nombre de la Carpeta:
21.12 +FileChooser.folderNameLabelMnemonic=78
21.13 FileChooser.filesOfTypeLabelText=Archivos de Tipo:
21.14 +FileChooser.filesOfTypeLabelMnemonic=84
21.15 FileChooser.upFolderToolTipText=Subir un Nivel
21.16 FileChooser.upFolderAccessibleName=Arriba
21.17 FileChooser.homeFolderToolTipText=Inicio
22.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_fr.properties Thu Sep 15 18:53:28 2011 -0700
22.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_fr.properties Mon Sep 19 19:40:59 2011 -0700
22.3 @@ -19,10 +19,14 @@
22.4 ############ FILE CHOOSER STRINGS #############
22.5
22.6 FileChooser.lookInLabelText=Rechercher dans :
22.7 +FileChooser.lookInLabelMnemonic=73
22.8 FileChooser.saveInLabelText=Enregistrer dans :
22.9 FileChooser.fileNameLabelText=Nom du fichier :
22.10 +FileChooser.fileNameLabelMnemonic=78
22.11 FileChooser.folderNameLabelText=Nom du dossier :
22.12 +FileChooser.folderNameLabelMnemonic=78
22.13 FileChooser.filesOfTypeLabelText=Fichiers de type :
22.14 +FileChooser.filesOfTypeLabelMnemonic=84
22.15 FileChooser.upFolderToolTipText=Remonte d'un niveau.
22.16 FileChooser.upFolderAccessibleName=Monter
22.17 FileChooser.homeFolderToolTipText=R\u00E9pertoire d'origine
23.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_it.properties Thu Sep 15 18:53:28 2011 -0700
23.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_it.properties Mon Sep 19 19:40:59 2011 -0700
23.3 @@ -19,10 +19,14 @@
23.4 ############ FILE CHOOSER STRINGS #############
23.5
23.6 FileChooser.lookInLabelText=Cerca in:
23.7 +FileChooser.lookInLabelMnemonic=73
23.8 FileChooser.saveInLabelText=Salva in:
23.9 FileChooser.fileNameLabelText=Nome file:
23.10 +FileChooser.fileNameLabelMnemonic=78
23.11 FileChooser.folderNameLabelText=Nome della cartella:
23.12 +FileChooser.folderNameLabelMnemonic=78
23.13 FileChooser.filesOfTypeLabelText=Tipo file:
23.14 +FileChooser.filesOfTypeLabelMnemonic=84
23.15 FileChooser.upFolderToolTipText=Cartella superiore
23.16 FileChooser.upFolderAccessibleName=Superiore
23.17 FileChooser.homeFolderToolTipText=Home
24.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_ja.properties Thu Sep 15 18:53:28 2011 -0700
24.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_ja.properties Mon Sep 19 19:40:59 2011 -0700
24.3 @@ -19,10 +19,14 @@
24.4 ############ FILE CHOOSER STRINGS #############
24.5
24.6 FileChooser.lookInLabelText=\u53C2\u7167:
24.7 +FileChooser.lookInLabelMnemonic=73
24.8 FileChooser.saveInLabelText=\u4FDD\u5B58:
24.9 FileChooser.fileNameLabelText=\u30D5\u30A1\u30A4\u30EB\u540D:
24.10 +FileChooser.fileNameLabelMnemonic=78
24.11 FileChooser.folderNameLabelText=\u30D5\u30A9\u30EB\u30C0\u540D:
24.12 +FileChooser.folderNameLabelMnemonic=78
24.13 FileChooser.filesOfTypeLabelText=\u30D5\u30A1\u30A4\u30EB\u306E\u30BF\u30A4\u30D7:
24.14 +FileChooser.filesOfTypeLabelMnemonic=84
24.15 FileChooser.upFolderToolTipText=1\u30EC\u30D9\u30EB\u4E0A\u3078
24.16 FileChooser.upFolderAccessibleName=\u4E0A\u3078
24.17 FileChooser.homeFolderToolTipText=\u30DB\u30FC\u30E0
25.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_ko.properties Thu Sep 15 18:53:28 2011 -0700
25.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_ko.properties Mon Sep 19 19:40:59 2011 -0700
25.3 @@ -19,10 +19,14 @@
25.4 ############ FILE CHOOSER STRINGS #############
25.5
25.6 FileChooser.lookInLabelText=\uAC80\uC0C9 \uC704\uCE58:
25.7 +FileChooser.lookInLabelMnemonic=73
25.8 FileChooser.saveInLabelText=\uC800\uC7A5 \uC704\uCE58:
25.9 FileChooser.fileNameLabelText=\uD30C\uC77C \uC774\uB984:
25.10 +FileChooser.fileNameLabelMnemonic=78
25.11 FileChooser.folderNameLabelText=\uD3F4\uB354 \uC774\uB984:
25.12 +FileChooser.folderNameLabelMnemonic=78
25.13 FileChooser.filesOfTypeLabelText=\uD30C\uC77C \uC720\uD615:
25.14 +FileChooser.filesOfTypeLabelMnemonic=84
25.15 FileChooser.upFolderToolTipText=\uD55C \uB808\uBCA8 \uC704\uB85C
25.16 FileChooser.upFolderAccessibleName=\uC704\uB85C
25.17 FileChooser.homeFolderToolTipText=\uD648
26.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_pt_BR.properties Thu Sep 15 18:53:28 2011 -0700
26.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_pt_BR.properties Mon Sep 19 19:40:59 2011 -0700
26.3 @@ -19,10 +19,14 @@
26.4 ############ FILE CHOOSER STRINGS #############
26.5
26.6 FileChooser.lookInLabelText=Consultar em:
26.7 +FileChooser.lookInLabelMnemonic=73
26.8 FileChooser.saveInLabelText=Salvar em:
26.9 FileChooser.fileNameLabelText=Nome do arquivo:
26.10 +FileChooser.fileNameLabelMnemonic=78
26.11 FileChooser.folderNameLabelText=Nome da pasta:
26.12 +FileChooser.folderNameLabelMnemonic=78
26.13 FileChooser.filesOfTypeLabelText=Arquivos do tipo:
26.14 +FileChooser.filesOfTypeLabelMnemonic=84
26.15 FileChooser.upFolderToolTipText=Um N\u00EDvel Acima
26.16 FileChooser.upFolderAccessibleName=Acima
26.17 FileChooser.homeFolderToolTipText=In\u00EDcio
27.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_sv.properties Thu Sep 15 18:53:28 2011 -0700
27.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_sv.properties Mon Sep 19 19:40:59 2011 -0700
27.3 @@ -19,10 +19,14 @@
27.4 ############ FILE CHOOSER STRINGS #############
27.5
27.6 FileChooser.lookInLabelText=Leta i:
27.7 +FileChooser.lookInLabelMnemonic=73
27.8 FileChooser.saveInLabelText=Spara i:
27.9 FileChooser.fileNameLabelText=Filnamn:
27.10 +FileChooser.fileNameLabelMnemonic=78
27.11 FileChooser.folderNameLabelText=Mapp:
27.12 +FileChooser.folderNameLabelMnemonic=78
27.13 FileChooser.filesOfTypeLabelText=Filformat:
27.14 +FileChooser.filesOfTypeLabelMnemonic=84
27.15 FileChooser.upFolderToolTipText=Upp en niv\u00E5
27.16 FileChooser.upFolderAccessibleName=Upp
27.17 FileChooser.homeFolderToolTipText=Hem
28.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_zh_CN.properties Thu Sep 15 18:53:28 2011 -0700
28.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_zh_CN.properties Mon Sep 19 19:40:59 2011 -0700
28.3 @@ -19,10 +19,14 @@
28.4 ############ FILE CHOOSER STRINGS #############
28.5
28.6 FileChooser.lookInLabelText=\u67E5\u770B:
28.7 +FileChooser.lookInLabelMnemonic=73
28.8 FileChooser.saveInLabelText=\u4FDD\u5B58:
28.9 FileChooser.fileNameLabelText=\u6587\u4EF6\u540D:
28.10 +FileChooser.fileNameLabelMnemonic=78
28.11 FileChooser.folderNameLabelText=\u6587\u4EF6\u5939\u540D:
28.12 +FileChooser.folderNameLabelMnemonic=78
28.13 FileChooser.filesOfTypeLabelText=\u6587\u4EF6\u7C7B\u578B:
28.14 +FileChooser.filesOfTypeLabelMnemonic=84
28.15 FileChooser.upFolderToolTipText=\u5411\u4E0A\u4E00\u7EA7
28.16 FileChooser.upFolderAccessibleName=\u5411\u4E0A
28.17 FileChooser.homeFolderToolTipText=\u4E3B\u76EE\u5F55
29.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_zh_TW.properties Thu Sep 15 18:53:28 2011 -0700
29.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/resources/windows_zh_TW.properties Mon Sep 19 19:40:59 2011 -0700
29.3 @@ -19,10 +19,14 @@
29.4 ############ FILE CHOOSER STRINGS #############
29.5
29.6 FileChooser.lookInLabelText=\u67E5\u8A62:
29.7 +FileChooser.lookInLabelMnemonic=73
29.8 FileChooser.saveInLabelText=\u5132\u5B58\u65BC:
29.9 FileChooser.fileNameLabelText=\u6A94\u6848\u540D\u7A31:
29.10 +FileChooser.fileNameLabelMnemonic=78
29.11 FileChooser.folderNameLabelText=\u8CC7\u6599\u593E\u540D\u7A31:
29.12 +FileChooser.folderNameLabelMnemonic=78
29.13 FileChooser.filesOfTypeLabelText=\u6A94\u6848\u985E\u578B:
29.14 +FileChooser.filesOfTypeLabelMnemonic=84
29.15 FileChooser.upFolderToolTipText=\u5F80\u4E0A\u4E00\u5C64
29.16 FileChooser.upFolderAccessibleName=\u5F80\u4E0A
29.17 FileChooser.homeFolderToolTipText=\u4E3B\u76EE\u9304
30.1 --- a/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java Thu Sep 15 18:53:28 2011 -0700
30.2 +++ b/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java Mon Sep 19 19:40:59 2011 -0700
30.3 @@ -186,7 +186,7 @@
30.4 newclone = (SnmpCounter64) super.clone() ;
30.5 newclone.value = value ;
30.6 } catch (CloneNotSupportedException e) {
30.7 - throw new InternalError() ; // vm bug.
30.8 + throw new InternalError(e) ; // vm bug.
30.9 }
30.10 return newclone ;
30.11 }
31.1 --- a/src/share/classes/com/sun/jmx/snmp/SnmpInt.java Thu Sep 15 18:53:28 2011 -0700
31.2 +++ b/src/share/classes/com/sun/jmx/snmp/SnmpInt.java Mon Sep 19 19:40:59 2011 -0700
31.3 @@ -232,7 +232,7 @@
31.4 newclone = (SnmpInt) super.clone() ;
31.5 newclone.value = value ;
31.6 } catch (CloneNotSupportedException e) {
31.7 - throw new InternalError() ; // vm bug.
31.8 + throw new InternalError(e) ; // vm bug.
31.9 }
31.10 return newclone ;
31.11 }
32.1 --- a/src/share/classes/com/sun/jmx/snmp/SnmpNull.java Thu Sep 15 18:53:28 2011 -0700
32.2 +++ b/src/share/classes/com/sun/jmx/snmp/SnmpNull.java Mon Sep 19 19:40:59 2011 -0700
32.3 @@ -129,7 +129,7 @@
32.4 newclone = (SnmpNull) super.clone() ;
32.5 newclone.tag = tag ;
32.6 } catch (CloneNotSupportedException e) {
32.7 - throw new InternalError() ; // vm bug.
32.8 + throw new InternalError(e) ; // vm bug.
32.9 }
32.10 return newclone ;
32.11 }
33.1 --- a/src/share/classes/com/sun/jmx/snmp/SnmpString.java Thu Sep 15 18:53:28 2011 -0700
33.2 +++ b/src/share/classes/com/sun/jmx/snmp/SnmpString.java Mon Sep 19 19:40:59 2011 -0700
33.3 @@ -250,7 +250,7 @@
33.4 newclone.value = new byte[value.length] ;
33.5 System.arraycopy(value, 0, newclone.value, 0, value.length) ;
33.6 } catch (CloneNotSupportedException e) {
33.7 - throw new InternalError() ; // vm bug.
33.8 + throw new InternalError(e) ; // vm bug.
33.9 }
33.10 return newclone ;
33.11 }
34.1 --- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java Thu Sep 15 18:53:28 2011 -0700
34.2 +++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java Mon Sep 19 19:40:59 2011 -0700
34.3 @@ -921,7 +921,7 @@
34.4 SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
34.5 "newTooBigMessage", "Internal error", x);
34.6 }
34.7 - throw new InternalError() ;
34.8 + throw new InternalError(x) ;
34.9 }
34.10
34.11 return result ;
35.1 --- a/src/share/classes/com/sun/security/auth/module/NTSystem.java Thu Sep 15 18:53:28 2011 -0700
35.2 +++ b/src/share/classes/com/sun/security/auth/module/NTSystem.java Mon Sep 19 19:40:59 2011 -0700
35.3 @@ -1,5 +1,5 @@
35.4 /*
35.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
35.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
35.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35.8 *
35.9 * This code is free software; you can redistribute it and/or modify it
35.10 @@ -33,6 +33,7 @@
35.11 public class NTSystem {
35.12
35.13 private native void getCurrent(boolean debug);
35.14 + private native long getImpersonationToken0();
35.15
35.16 private String userName;
35.17 private String domain;
35.18 @@ -132,10 +133,14 @@
35.19 *
35.20 * @return an impersonation token for the current NT user.
35.21 */
35.22 - public long getImpersonationToken() {
35.23 + public synchronized long getImpersonationToken() {
35.24 + if (impersonationToken == 0) {
35.25 + impersonationToken = getImpersonationToken0();
35.26 + }
35.27 return impersonationToken;
35.28 }
35.29
35.30 +
35.31 private void loadNative() {
35.32 System.loadLibrary("jaas_nt");
35.33 }
36.1 --- a/src/share/classes/com/sun/servicetag/BrowserSupport.java Thu Sep 15 18:53:28 2011 -0700
36.2 +++ b/src/share/classes/com/sun/servicetag/BrowserSupport.java Mon Sep 19 19:40:59 2011 -0700
36.3 @@ -77,9 +77,7 @@
36.4 result = (Boolean) isDesktopSupportedMethod.invoke(null);
36.5 } catch (IllegalAccessException e) {
36.6 // should never reach here
36.7 - InternalError x =
36.8 - new InternalError("Desktop.getDesktop() method not found");
36.9 - x.initCause(e);
36.10 + throw new InternalError("Desktop.getDesktop() method not found", e);
36.11 } catch (InvocationTargetException e) {
36.12 // browser not supported
36.13 if (Util.isVerbose()) {
36.14 @@ -101,28 +99,10 @@
36.15 result = (Boolean) isSupportedMethod.invoke(desktopObj, browseField.get(null));
36.16 supported = result.booleanValue();
36.17 }
36.18 - } catch (ClassNotFoundException e) {
36.19 - // browser not supported
36.20 - if (Util.isVerbose()) {
36.21 - e.printStackTrace();
36.22 - }
36.23 - } catch (NoSuchMethodException e) {
36.24 - // browser not supported
36.25 - if (Util.isVerbose()) {
36.26 - e.printStackTrace();
36.27 - }
36.28 - } catch (NoSuchFieldException e) {
36.29 - // browser not supported
36.30 - if (Util.isVerbose()) {
36.31 - e.printStackTrace();
36.32 - }
36.33 } catch (IllegalAccessException e) {
36.34 // should never reach here
36.35 - InternalError x =
36.36 - new InternalError("Desktop.getDesktop() method not found");
36.37 - x.initCause(e);
36.38 - throw x;
36.39 - } catch (InvocationTargetException e) {
36.40 + throw new InternalError("Desktop.getDesktop() method not found", e);
36.41 + } catch (ReflectiveOperationException e) {
36.42 // browser not supported
36.43 if (Util.isVerbose()) {
36.44 e.printStackTrace();
36.45 @@ -175,10 +155,7 @@
36.46 browseMethod.invoke(desktop, uri);
36.47 } catch (IllegalAccessException e) {
36.48 // should never reach here
36.49 - InternalError x =
36.50 - new InternalError("Desktop.getDesktop() method not found");
36.51 - x.initCause(e);
36.52 - throw x;
36.53 + throw new InternalError("Desktop.getDesktop() method not found", e);
36.54 } catch (InvocationTargetException e) {
36.55 Throwable x = e.getCause();
36.56 if (x != null) {
37.1 --- a/src/share/classes/com/sun/servicetag/Installer.java Thu Sep 15 18:53:28 2011 -0700
37.2 +++ b/src/share/classes/com/sun/servicetag/Installer.java Mon Sep 19 19:40:59 2011 -0700
37.3 @@ -61,8 +61,8 @@
37.4 private static RegistrationData registration;
37.5 private static boolean supportRegistration;
37.6 private static String registerHtmlParent;
37.7 - private static Set<Locale> supportedLocales = new HashSet<Locale>();
37.8 - private static Properties swordfishProps = null;
37.9 + private static Set<Locale> supportedLocales = new HashSet<>();
37.10 + private static Properties svcTagProps = null;
37.11 private static String[] jreArchs = null;
37.12 static {
37.13 String dir = System.getProperty(SVCTAG_DIR_PATH);
37.14 @@ -94,7 +94,7 @@
37.15 boolean cleanup = false;
37.16 try {
37.17 // Check if we have the swordfish entries for this JRE version
37.18 - if (loadSwordfishEntries() == null) {
37.19 + if (loadServiceTagProps() == null) {
37.20 return null;
37.21 }
37.22
37.23 @@ -144,18 +144,14 @@
37.24 return registration;
37.25 }
37.26 if (regXmlFile.exists()) {
37.27 - BufferedInputStream in = null;
37.28 - try {
37.29 - in = new BufferedInputStream(new FileInputStream(regXmlFile));
37.30 + try (BufferedInputStream in =
37.31 + new BufferedInputStream(new FileInputStream(regXmlFile)))
37.32 + {
37.33 registration = RegistrationData.loadFromXML(in);
37.34 } catch (IllegalArgumentException ex) {
37.35 System.err.println("Error: Bad registration data \"" +
37.36 regXmlFile + "\":" + ex.getMessage());
37.37 throw ex;
37.38 - } finally {
37.39 - if (in != null) {
37.40 - in.close();
37.41 - }
37.42 }
37.43 } else {
37.44 registration = new RegistrationData();
37.45 @@ -186,18 +182,14 @@
37.46 deleteRegistrationHtmlPage();
37.47 getRegistrationHtmlPage();
37.48
37.49 - BufferedOutputStream out = null;
37.50 - try {
37.51 - out = new BufferedOutputStream(new FileOutputStream(regXmlFile));
37.52 + try (BufferedOutputStream out =
37.53 + new BufferedOutputStream(new FileOutputStream(regXmlFile)))
37.54 + {
37.55 getRegistrationData().storeToXML(out);
37.56 } catch (IllegalArgumentException ex) {
37.57 System.err.println("Error: Bad registration data \"" +
37.58 regXmlFile + "\":" + ex.getMessage());
37.59 throw ex;
37.60 - } finally {
37.61 - if (out != null) {
37.62 - out.close();
37.63 - }
37.64 }
37.65 }
37.66
37.67 @@ -206,11 +198,9 @@
37.68 * or empty set if file not exists.
37.69 */
37.70 private static Set<String> getInstalledURNs() throws IOException {
37.71 - Set<String> urnSet = new HashSet<String>();
37.72 + Set<String> urnSet = new HashSet<>();
37.73 if (serviceTagFile.exists()) {
37.74 - BufferedReader in = null;
37.75 - try {
37.76 - in = new BufferedReader(new FileReader(serviceTagFile));
37.77 + try (BufferedReader in = new BufferedReader(new FileReader(serviceTagFile))) {
37.78 String urn;
37.79 while ((urn = in.readLine()) != null) {
37.80 urn = urn.trim();
37.81 @@ -218,10 +208,6 @@
37.82 urnSet.add(urn);
37.83 }
37.84 }
37.85 - } finally {
37.86 - if (in != null) {
37.87 - in.close();
37.88 - }
37.89 }
37.90 }
37.91 return urnSet;
37.92 @@ -237,9 +223,9 @@
37.93 private static ServiceTag[] getJavaServiceTagArray() throws IOException {
37.94 RegistrationData regData = getRegistrationData();
37.95 Set<ServiceTag> svcTags = regData.getServiceTags();
37.96 - Set<ServiceTag> result = new HashSet<ServiceTag>();
37.97 + Set<ServiceTag> result = new HashSet<>();
37.98
37.99 - Properties props = loadSwordfishEntries();
37.100 + Properties props = loadServiceTagProps();
37.101 String jdkUrn = props.getProperty("servicetag.jdk.urn");
37.102 String jreUrn = props.getProperty("servicetag.jre.urn");
37.103 for (ServiceTag st : svcTags) {
37.104 @@ -343,8 +329,7 @@
37.105 }
37.106
37.107 private static ServiceTag newServiceTag(String svcTagSource) throws IOException {
37.108 - // Load the swoRDFish information for the service tag creation
37.109 - Properties props = loadSwordfishEntries();
37.110 + Properties props = loadServiceTagProps();
37.111
37.112 // Determine the product URN and name
37.113 String productURN;
37.114 @@ -442,52 +427,35 @@
37.115 return;
37.116 }
37.117
37.118 - PrintWriter out = null;
37.119 - try {
37.120 - out = new PrintWriter(serviceTagFile);
37.121 -
37.122 + try (PrintWriter out = new PrintWriter(serviceTagFile)) {
37.123 ServiceTag[] javaSvcTags = getJavaServiceTagArray();
37.124 for (ServiceTag st : javaSvcTags) {
37.125 // Write the instance_run to the servicetag file
37.126 String instanceURN = st.getInstanceURN();
37.127 out.println(instanceURN);
37.128 }
37.129 - } finally {
37.130 - if (out != null) {
37.131 - out.close();
37.132 - }
37.133 }
37.134 }
37.135
37.136 /**
37.137 - * Load the values associated with the swoRDFish metadata entries
37.138 - * for Java SE. The swoRDFish metadata entries are different for
37.139 - * different release.
37.140 + * Load the properties for generating Java SE service tags.
37.141 *
37.142 * @param version Version of Java SE
37.143 */
37.144 - private static synchronized Properties loadSwordfishEntries() throws IOException {
37.145 - if (swordfishProps != null) {
37.146 - return swordfishProps;
37.147 + private static synchronized Properties loadServiceTagProps() throws IOException {
37.148 + if (svcTagProps != null) {
37.149 + return svcTagProps;
37.150 }
37.151
37.152 - // The version string for Java SE 6 is 1.6.0
37.153 - // We just need the minor number in the version string
37.154 - int version = Util.getJdkVersion();
37.155 -
37.156 - String filename = "/com/sun/servicetag/resources/javase_" +
37.157 - version + "_swordfish.properties";
37.158 - InputStream in = Installer.class.getResourceAsStream(filename);
37.159 - if (in == null) {
37.160 - return null;
37.161 + // For Java SE 8 and later releases, JDK and JRE both use
37.162 + // the same product number. The sworRDFish metadata were
37.163 + // for legacy Sun part number.
37.164 + String filename = "/com/sun/servicetag/resources/javase_servicetag.properties";
37.165 + try (InputStream in = Installer.class.getResourceAsStream(filename)) {
37.166 + svcTagProps = new Properties();
37.167 + svcTagProps.load(in);
37.168 }
37.169 - swordfishProps = new Properties();
37.170 - try {
37.171 - swordfishProps.load(in);
37.172 - } finally {
37.173 - in.close();
37.174 - }
37.175 - return swordfishProps;
37.176 + return svcTagProps;
37.177 }
37.178
37.179 /**
37.180 @@ -546,7 +514,7 @@
37.181 return jreArchs;
37.182 }
37.183
37.184 - Set<String> archs = new HashSet<String>();
37.185 + Set<String> archs = new HashSet<>();
37.186
37.187 String os = System.getProperty("os.name");
37.188 if (os.equals("SunOS") || os.equals("Linux")) {
37.189 @@ -681,16 +649,16 @@
37.190 String country = locale.getCountry();
37.191 String variant = locale.getVariant();
37.192
37.193 - List<Locale> locales = new ArrayList<Locale>(3);
37.194 + List<Locale> locales = new ArrayList<>(3);
37.195 if (variant.length() > 0) {
37.196 locales.add(locale);
37.197 }
37.198 if (country.length() > 0) {
37.199 - locales.add((locales.size() == 0) ?
37.200 + locales.add((locales.isEmpty()) ?
37.201 locale : new Locale(language, country, ""));
37.202 }
37.203 if (language.length() > 0) {
37.204 - locales.add((locales.size() == 0) ?
37.205 + locales.add((locales.isEmpty()) ?
37.206 locale : new Locale(language, "", ""));
37.207 }
37.208 return locales;
37.209 @@ -788,14 +756,11 @@
37.210 // Format the registration data in one single line
37.211 StringBuilder payload = new StringBuilder();
37.212 String xml = regData.toString().replaceAll("\"", "%22");
37.213 - BufferedReader reader = new BufferedReader(new StringReader(xml));
37.214 - try {
37.215 + try (BufferedReader reader = new BufferedReader(new StringReader(xml))) {
37.216 String line = null;
37.217 while ((line = reader.readLine()) != null) {
37.218 payload.append(line.trim());
37.219 }
37.220 - } finally {
37.221 - reader.close();
37.222 }
37.223
37.224 String resourceFilename = "/com/sun/servicetag/resources/register";
38.1 --- a/src/share/classes/com/sun/servicetag/RegistrationDocument.java Thu Sep 15 18:53:28 2011 -0700
38.2 +++ b/src/share/classes/com/sun/servicetag/RegistrationDocument.java Mon Sep 19 19:40:59 2011 -0700
38.3 @@ -150,9 +150,7 @@
38.4 } catch (ParserConfigurationException pce) {
38.5 // Parser with specific options can't be built
38.6 // should not reach here
38.7 - InternalError x = new InternalError("Error in creating the new document");
38.8 - x.initCause(pce);
38.9 - throw x;
38.10 + throw new InternalError("Error in creating the new document", pce);
38.11 }
38.12 }
38.13
38.14 @@ -172,9 +170,7 @@
38.15 } catch (ParserConfigurationException pce) {
38.16 // Parser with specified options can't be built
38.17 // should not reach here
38.18 - InternalError x = new InternalError("Error in creating the new document");
38.19 - x.initCause(pce);
38.20 - throw x;
38.21 + throw new InternalError("Error in creating the new document", pce);
38.22 }
38.23 }
38.24
38.25 @@ -195,20 +191,14 @@
38.26 new StreamResult(new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))));
38.27 } catch (UnsupportedEncodingException ue) {
38.28 // Should not reach here
38.29 - InternalError x = new InternalError("Error generated during transformation");
38.30 - x.initCause(ue);
38.31 - throw x;
38.32 + throw new InternalError("Error generated during transformation", ue);
38.33 } catch (TransformerConfigurationException tce) {
38.34 // Error generated by the parser
38.35 // Should not reach here
38.36 - InternalError x = new InternalError("Error in creating the new document");
38.37 - x.initCause(tce);
38.38 - throw x;
38.39 + throw new InternalError("Error in creating the new document", tce);
38.40 } catch (TransformerException te) {
38.41 // Error generated by the transformer
38.42 - InternalError x = new InternalError("Error generated during transformation");
38.43 - x.initCause(te);
38.44 - throw x;
38.45 + throw new InternalError("Error generated during transformation", te);
38.46 }
38.47 }
38.48
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/src/share/classes/com/sun/servicetag/resources/javase_servicetag.properties Mon Sep 19 19:40:59 2011 -0700
39.3 @@ -0,0 +1,29 @@
39.4 +# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
39.5 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39.6 +#
39.7 +# This code is free software; you can redistribute it and/or modify it
39.8 +# under the terms of the GNU General Public License version 2 only, as
39.9 +# published by the Free Software Foundation. Oracle designates this
39.10 +# particular file as subject to the "Classpath" exception as provided
39.11 +# by Oracle in the LICENSE file that accompanied this code.
39.12 +#
39.13 +# This code is distributed in the hope that it will be useful, but WITHOUT
39.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39.15 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39.16 +# version 2 for more details (a copy is included in the LICENSE file that
39.17 +# accompanied this code).
39.18 +#
39.19 +# You should have received a copy of the GNU General Public License version
39.20 +# 2 along with this work; if not, write to the Free Software Foundation,
39.21 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39.22 +#
39.23 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39.24 +# or visit www.oracle.com if you need additional information or have any
39.25 +# questions.
39.26 +
39.27 +servicetag.jdk.urn = Q8549
39.28 +servicetag.jdk.name = Java Development Kit
39.29 +servicetag.jre.urn = Q8549
39.30 +servicetag.jre.name = Java Runtime Environment
39.31 +servicetag.parent.urn = Q8549
39.32 +servicetag.parent.name = Java Platform, Standard Edition
40.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal.properties Thu Sep 15 18:53:28 2011 -0700
40.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal.properties Mon Sep 19 19:40:59 2011 -0700
40.3 @@ -19,10 +19,14 @@
40.4 ############ FILE CHOOSER STRINGS #############
40.5
40.6 FileChooser.lookInLabelText=Look In:
40.7 +FileChooser.lookInLabelMnemonic=73
40.8 FileChooser.saveInLabelText=Save In:
40.9 FileChooser.fileNameLabelText=File Name:
40.10 +FileChooser.fileNameLabelMnemonic=78
40.11 FileChooser.folderNameLabelText=Folder name:
40.12 +FileChooser.folderNameLabelMnemonic=78
40.13 FileChooser.filesOfTypeLabelText=Files of Type:
40.14 +FileChooser.filesOfTypeLabelMnemonic=84
40.15 FileChooser.upFolderToolTipText=Up One Level
40.16 FileChooser.upFolderAccessibleName=Up
40.17 FileChooser.homeFolderToolTipText=Home
41.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_de.properties Thu Sep 15 18:53:28 2011 -0700
41.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_de.properties Mon Sep 19 19:40:59 2011 -0700
41.3 @@ -19,10 +19,14 @@
41.4 ############ FILE CHOOSER STRINGS #############
41.5
41.6 FileChooser.lookInLabelText=Suchen in:
41.7 +FileChooser.lookInLabelMnemonic=73
41.8 FileChooser.saveInLabelText=Speichern in:
41.9 FileChooser.fileNameLabelText=Dateiname:
41.10 +FileChooser.fileNameLabelMnemonic=78
41.11 FileChooser.folderNameLabelText=Ordnername:
41.12 +FileChooser.folderNameLabelMnemonic=78
41.13 FileChooser.filesOfTypeLabelText=Dateityp:
41.14 +FileChooser.filesOfTypeLabelMnemonic=84
41.15 FileChooser.upFolderToolTipText=Eine Ebene h\u00F6her
41.16 FileChooser.upFolderAccessibleName=Nach oben
41.17 FileChooser.homeFolderToolTipText=Home
42.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_es.properties Thu Sep 15 18:53:28 2011 -0700
42.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_es.properties Mon Sep 19 19:40:59 2011 -0700
42.3 @@ -19,10 +19,14 @@
42.4 ############ FILE CHOOSER STRINGS #############
42.5
42.6 FileChooser.lookInLabelText=Buscar en:
42.7 +FileChooser.lookInLabelMnemonic=73
42.8 FileChooser.saveInLabelText=Guardar en:
42.9 FileChooser.fileNameLabelText=Nombre de Archivo:
42.10 +FileChooser.fileNameLabelMnemonic=78
42.11 FileChooser.folderNameLabelText=Nombre de la Carpeta:
42.12 +FileChooser.folderNameLabelMnemonic=78
42.13 FileChooser.filesOfTypeLabelText=Archivos de Tipo:
42.14 +FileChooser.filesOfTypeLabelMnemonic=84
42.15 FileChooser.upFolderToolTipText=Subir un Nivel
42.16 FileChooser.upFolderAccessibleName=Arriba
42.17 FileChooser.homeFolderToolTipText=Inicio
43.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_fr.properties Thu Sep 15 18:53:28 2011 -0700
43.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_fr.properties Mon Sep 19 19:40:59 2011 -0700
43.3 @@ -19,10 +19,14 @@
43.4 ############ FILE CHOOSER STRINGS #############
43.5
43.6 FileChooser.lookInLabelText=Rechercher dans :
43.7 +FileChooser.lookInLabelMnemonic=73
43.8 FileChooser.saveInLabelText=Enregistrer dans :
43.9 FileChooser.fileNameLabelText=Nom du fichier :
43.10 +FileChooser.fileNameLabelMnemonic=78
43.11 FileChooser.folderNameLabelText=Nom du dossier :
43.12 +FileChooser.folderNameLabelMnemonic=78
43.13 FileChooser.filesOfTypeLabelText=Fichiers de type :
43.14 +FileChooser.filesOfTypeLabelMnemonic=84
43.15 FileChooser.upFolderToolTipText=Remonte d'un niveau.
43.16 FileChooser.upFolderAccessibleName=Monter
43.17 FileChooser.homeFolderToolTipText=R\u00E9pertoire d'origine
44.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_it.properties Thu Sep 15 18:53:28 2011 -0700
44.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_it.properties Mon Sep 19 19:40:59 2011 -0700
44.3 @@ -19,10 +19,14 @@
44.4 ############ FILE CHOOSER STRINGS #############
44.5
44.6 FileChooser.lookInLabelText=Cerca in:
44.7 +FileChooser.lookInLabelMnemonic=73
44.8 FileChooser.saveInLabelText=Salva in:
44.9 FileChooser.fileNameLabelText=Nome file:
44.10 +FileChooser.fileNameLabelMnemonic=78
44.11 FileChooser.folderNameLabelText=Nome della cartella:
44.12 +FileChooser.folderNameLabelMnemonic=78
44.13 FileChooser.filesOfTypeLabelText=Tipo file:
44.14 +FileChooser.filesOfTypeLabelMnemonic=84
44.15 FileChooser.upFolderToolTipText=Cartella superiore
44.16 FileChooser.upFolderAccessibleName=Superiore
44.17 FileChooser.homeFolderToolTipText=Home
45.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_ja.properties Thu Sep 15 18:53:28 2011 -0700
45.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_ja.properties Mon Sep 19 19:40:59 2011 -0700
45.3 @@ -19,10 +19,14 @@
45.4 ############ FILE CHOOSER STRINGS #############
45.5
45.6 FileChooser.lookInLabelText=\u53C2\u7167:
45.7 +FileChooser.lookInLabelMnemonic=73
45.8 FileChooser.saveInLabelText=\u4FDD\u5B58:
45.9 FileChooser.fileNameLabelText=\u30D5\u30A1\u30A4\u30EB\u540D:
45.10 +FileChooser.fileNameLabelMnemonic=78
45.11 FileChooser.folderNameLabelText=\u30D5\u30A9\u30EB\u30C0\u540D:
45.12 +FileChooser.folderNameLabelMnemonic=78
45.13 FileChooser.filesOfTypeLabelText=\u30D5\u30A1\u30A4\u30EB\u306E\u30BF\u30A4\u30D7:
45.14 +FileChooser.filesOfTypeLabelMnemonic=84
45.15 FileChooser.upFolderToolTipText=1\u30EC\u30D9\u30EB\u4E0A\u3078
45.16 FileChooser.upFolderAccessibleName=\u4E0A\u3078
45.17 FileChooser.homeFolderToolTipText=\u30DB\u30FC\u30E0
46.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_ko.properties Thu Sep 15 18:53:28 2011 -0700
46.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_ko.properties Mon Sep 19 19:40:59 2011 -0700
46.3 @@ -19,10 +19,14 @@
46.4 ############ FILE CHOOSER STRINGS #############
46.5
46.6 FileChooser.lookInLabelText=\uAC80\uC0C9 \uC704\uCE58:
46.7 +FileChooser.lookInLabelMnemonic=73
46.8 FileChooser.saveInLabelText=\uC800\uC7A5 \uC704\uCE58:
46.9 FileChooser.fileNameLabelText=\uD30C\uC77C \uC774\uB984:
46.10 +FileChooser.fileNameLabelMnemonic=78
46.11 FileChooser.folderNameLabelText=\uD3F4\uB354 \uC774\uB984:
46.12 +FileChooser.folderNameLabelMnemonic=78
46.13 FileChooser.filesOfTypeLabelText=\uD30C\uC77C \uC720\uD615:
46.14 +FileChooser.filesOfTypeLabelMnemonic=84
46.15 FileChooser.upFolderToolTipText=\uD55C \uB808\uBCA8 \uC704\uB85C
46.16 FileChooser.upFolderAccessibleName=\uC704\uB85C
46.17 FileChooser.homeFolderToolTipText=\uD648
47.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_pt_BR.properties Thu Sep 15 18:53:28 2011 -0700
47.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_pt_BR.properties Mon Sep 19 19:40:59 2011 -0700
47.3 @@ -19,10 +19,14 @@
47.4 ############ FILE CHOOSER STRINGS #############
47.5
47.6 FileChooser.lookInLabelText=Consultar Em:
47.7 +FileChooser.lookInLabelMnemonic=73
47.8 FileChooser.saveInLabelText=Salvar Em:
47.9 FileChooser.fileNameLabelText=Nome do Arquivo:
47.10 +FileChooser.fileNameLabelMnemonic=78
47.11 FileChooser.folderNameLabelText=Nome da pasta:
47.12 +FileChooser.folderNameLabelMnemonic=78
47.13 FileChooser.filesOfTypeLabelText=Arquivos do Tipo:
47.14 +FileChooser.filesOfTypeLabelMnemonic=84
47.15 FileChooser.upFolderToolTipText=Um N\u00EDvel Acima
47.16 FileChooser.upFolderAccessibleName=Acima
47.17 FileChooser.homeFolderToolTipText=In\u00EDcio
48.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_sv.properties Thu Sep 15 18:53:28 2011 -0700
48.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_sv.properties Mon Sep 19 19:40:59 2011 -0700
48.3 @@ -19,10 +19,14 @@
48.4 ############ FILE CHOOSER STRINGS #############
48.5
48.6 FileChooser.lookInLabelText=Leta i:
48.7 +FileChooser.lookInLabelMnemonic=73
48.8 FileChooser.saveInLabelText=Spara i:
48.9 FileChooser.fileNameLabelText=Filnamn:
48.10 +FileChooser.fileNameLabelMnemonic=78
48.11 FileChooser.folderNameLabelText=Mapp:
48.12 +FileChooser.folderNameLabelMnemonic=78
48.13 FileChooser.filesOfTypeLabelText=Filformat:
48.14 +FileChooser.filesOfTypeLabelMnemonic=84
48.15 FileChooser.upFolderToolTipText=Upp en niv\u00E5
48.16 FileChooser.upFolderAccessibleName=Upp
48.17 FileChooser.homeFolderToolTipText=Hem
49.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_zh_CN.properties Thu Sep 15 18:53:28 2011 -0700
49.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_zh_CN.properties Mon Sep 19 19:40:59 2011 -0700
49.3 @@ -19,10 +19,14 @@
49.4 ############ FILE CHOOSER STRINGS #############
49.5
49.6 FileChooser.lookInLabelText=\u67E5\u770B:
49.7 +FileChooser.lookInLabelMnemonic=73
49.8 FileChooser.saveInLabelText=\u4FDD\u5B58:
49.9 FileChooser.fileNameLabelText=\u6587\u4EF6\u540D:
49.10 +FileChooser.fileNameLabelMnemonic=78
49.11 FileChooser.folderNameLabelText=\u6587\u4EF6\u5939\u540D:
49.12 +FileChooser.folderNameLabelMnemonic=78
49.13 FileChooser.filesOfTypeLabelText=\u6587\u4EF6\u7C7B\u578B:
49.14 +FileChooser.filesOfTypeLabelMnemonic=84
49.15 FileChooser.upFolderToolTipText=\u5411\u4E0A\u4E00\u7EA7
49.16 FileChooser.upFolderAccessibleName=\u5411\u4E0A
49.17 FileChooser.homeFolderToolTipText=\u4E3B\u76EE\u5F55
50.1 --- a/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_zh_TW.properties Thu Sep 15 18:53:28 2011 -0700
50.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/metal/resources/metal_zh_TW.properties Mon Sep 19 19:40:59 2011 -0700
50.3 @@ -19,10 +19,14 @@
50.4 ############ FILE CHOOSER STRINGS #############
50.5
50.6 FileChooser.lookInLabelText=\u67E5\u8A62:
50.7 +FileChooser.lookInLabelMnemonic=73
50.8 FileChooser.saveInLabelText=\u5132\u5B58\u65BC:
50.9 FileChooser.fileNameLabelText=\u6A94\u6848\u540D\u7A31:
50.10 +FileChooser.fileNameLabelMnemonic=78
50.11 FileChooser.folderNameLabelText=\u8CC7\u6599\u593E\u540D\u7A31:
50.12 +FileChooser.folderNameLabelMnemonic=78
50.13 FileChooser.filesOfTypeLabelText=\u6A94\u6848\u985E\u578B:
50.14 +FileChooser.filesOfTypeLabelMnemonic=84
50.15 FileChooser.upFolderToolTipText=\u5F80\u4E0A\u4E00\u5C64
50.16 FileChooser.upFolderAccessibleName=\u5F80\u4E0A
50.17 FileChooser.homeFolderToolTipText=\u4E3B\u76EE\u9304
51.1 --- a/src/share/classes/java/awt/BufferCapabilities.java Thu Sep 15 18:53:28 2011 -0700
51.2 +++ b/src/share/classes/java/awt/BufferCapabilities.java Mon Sep 19 19:40:59 2011 -0700
51.3 @@ -137,7 +137,7 @@
51.4 return super.clone();
51.5 } catch (CloneNotSupportedException e) {
51.6 // Since we implement Cloneable, this should never happen
51.7 - throw new InternalError();
51.8 + throw new InternalError(e);
51.9 }
51.10 }
51.11
52.1 --- a/src/share/classes/java/awt/Component.java Thu Sep 15 18:53:28 2011 -0700
52.2 +++ b/src/share/classes/java/awt/Component.java Mon Sep 19 19:40:59 2011 -0700
52.3 @@ -3776,11 +3776,10 @@
52.4 createBufferStrategy(numBuffers, bufferCaps);
52.5 return; // Success
52.6 } catch (AWTException e) {
52.7 - // Failed
52.8 - }
52.9 - // Code should never reach here (an unaccelerated blitting
52.10 - // strategy should always work)
52.11 - throw new InternalError("Could not create a buffer strategy");
52.12 + // Code should never reach here (an unaccelerated blitting
52.13 + // strategy should always work)
52.14 + throw new InternalError("Could not create a buffer strategy", e);
52.15 + }
52.16 }
52.17
52.18 /**
52.19 @@ -7910,7 +7909,7 @@
52.20 res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
52.21 }
52.22 }
52.23 - if (!res) {
52.24 + if (clearOnFailure && !res) {
52.25 if (focusLog.isLoggable(PlatformLogger.FINER)) {
52.26 focusLog.finer("clear global focus owner");
52.27 }
53.1 --- a/src/share/classes/java/awt/GridBagConstraints.java Thu Sep 15 18:53:28 2011 -0700
53.2 +++ b/src/share/classes/java/awt/GridBagConstraints.java Mon Sep 19 19:40:59 2011 -0700
53.3 @@ -653,7 +653,7 @@
53.4 return c;
53.5 } catch (CloneNotSupportedException e) {
53.6 // this shouldn't happen, since we are Cloneable
53.7 - throw new InternalError();
53.8 + throw new InternalError(e);
53.9 }
53.10 }
53.11
54.1 --- a/src/share/classes/java/awt/ImageCapabilities.java Thu Sep 15 18:53:28 2011 -0700
54.2 +++ b/src/share/classes/java/awt/ImageCapabilities.java Mon Sep 19 19:40:59 2011 -0700
54.3 @@ -74,7 +74,7 @@
54.4 return super.clone();
54.5 } catch (CloneNotSupportedException e) {
54.6 // Since we implement Cloneable, this should never happen
54.7 - throw new InternalError();
54.8 + throw new InternalError(e);
54.9 }
54.10 }
54.11
55.1 --- a/src/share/classes/java/awt/Insets.java Thu Sep 15 18:53:28 2011 -0700
55.2 +++ b/src/share/classes/java/awt/Insets.java Mon Sep 19 19:40:59 2011 -0700
55.3 @@ -177,7 +177,7 @@
55.4 return super.clone();
55.5 } catch (CloneNotSupportedException e) {
55.6 // this shouldn't happen, since we are Cloneable
55.7 - throw new InternalError();
55.8 + throw new InternalError(e);
55.9 }
55.10 }
55.11 /**
56.1 --- a/src/share/classes/java/awt/JobAttributes.java Thu Sep 15 18:53:28 2011 -0700
56.2 +++ b/src/share/classes/java/awt/JobAttributes.java Mon Sep 19 19:40:59 2011 -0700
56.3 @@ -361,7 +361,7 @@
56.4 return super.clone();
56.5 } catch (CloneNotSupportedException e) {
56.6 // Since we implement Cloneable, this should never happen
56.7 - throw new InternalError();
56.8 + throw new InternalError(e);
56.9 }
56.10 }
56.11
57.1 --- a/src/share/classes/java/awt/PageAttributes.java Thu Sep 15 18:53:28 2011 -0700
57.2 +++ b/src/share/classes/java/awt/PageAttributes.java Mon Sep 19 19:40:59 2011 -0700
57.3 @@ -969,7 +969,7 @@
57.4 return super.clone();
57.5 } catch (CloneNotSupportedException e) {
57.6 // Since we implement Cloneable, this should never happen
57.7 - throw new InternalError();
57.8 + throw new InternalError(e);
57.9 }
57.10 }
57.11
58.1 --- a/src/share/classes/java/awt/RenderingHints.java Thu Sep 15 18:53:28 2011 -0700
58.2 +++ b/src/share/classes/java/awt/RenderingHints.java Mon Sep 19 19:40:59 2011 -0700
58.3 @@ -1276,7 +1276,7 @@
58.4 }
58.5 } catch (CloneNotSupportedException e) {
58.6 // this shouldn't happen, since we are Cloneable
58.7 - throw new InternalError();
58.8 + throw new InternalError(e);
58.9 }
58.10
58.11 return rh;
59.1 --- a/src/share/classes/java/awt/font/TextLayout.java Thu Sep 15 18:53:28 2011 -0700
59.2 +++ b/src/share/classes/java/awt/font/TextLayout.java Mon Sep 19 19:40:59 2011 -0700
59.3 @@ -753,7 +753,7 @@
59.4 return super.clone();
59.5 }
59.6 catch (CloneNotSupportedException e) {
59.7 - throw new InternalError();
59.8 + throw new InternalError(e);
59.9 }
59.10 }
59.11
60.1 --- a/src/share/classes/java/awt/geom/AffineTransform.java Thu Sep 15 18:53:28 2011 -0700
60.2 +++ b/src/share/classes/java/awt/geom/AffineTransform.java Mon Sep 19 19:40:59 2011 -0700
60.3 @@ -3856,7 +3856,7 @@
60.4 return super.clone();
60.5 } catch (CloneNotSupportedException e) {
60.6 // this shouldn't happen, since we are Cloneable
60.7 - throw new InternalError();
60.8 + throw new InternalError(e);
60.9 }
60.10 }
60.11
61.1 --- a/src/share/classes/java/awt/geom/CubicCurve2D.java Thu Sep 15 18:53:28 2011 -0700
61.2 +++ b/src/share/classes/java/awt/geom/CubicCurve2D.java Mon Sep 19 19:40:59 2011 -0700
61.3 @@ -1569,7 +1569,7 @@
61.4 return super.clone();
61.5 } catch (CloneNotSupportedException e) {
61.6 // this shouldn't happen, since we are Cloneable
61.7 - throw new InternalError();
61.8 + throw new InternalError(e);
61.9 }
61.10 }
61.11 }
62.1 --- a/src/share/classes/java/awt/geom/Dimension2D.java Thu Sep 15 18:53:28 2011 -0700
62.2 +++ b/src/share/classes/java/awt/geom/Dimension2D.java Mon Sep 19 19:40:59 2011 -0700
62.3 @@ -108,7 +108,7 @@
62.4 return super.clone();
62.5 } catch (CloneNotSupportedException e) {
62.6 // this shouldn't happen, since we are Cloneable
62.7 - throw new InternalError();
62.8 + throw new InternalError(e);
62.9 }
62.10 }
62.11 }
63.1 --- a/src/share/classes/java/awt/geom/Line2D.java Thu Sep 15 18:53:28 2011 -0700
63.2 +++ b/src/share/classes/java/awt/geom/Line2D.java Mon Sep 19 19:40:59 2011 -0700
63.3 @@ -1122,7 +1122,7 @@
63.4 return super.clone();
63.5 } catch (CloneNotSupportedException e) {
63.6 // this shouldn't happen, since we are Cloneable
63.7 - throw new InternalError();
63.8 + throw new InternalError(e);
63.9 }
63.10 }
63.11 }
64.1 --- a/src/share/classes/java/awt/geom/Point2D.java Thu Sep 15 18:53:28 2011 -0700
64.2 +++ b/src/share/classes/java/awt/geom/Point2D.java Mon Sep 19 19:40:59 2011 -0700
64.3 @@ -393,7 +393,7 @@
64.4 return super.clone();
64.5 } catch (CloneNotSupportedException e) {
64.6 // this shouldn't happen, since we are Cloneable
64.7 - throw new InternalError();
64.8 + throw new InternalError(e);
64.9 }
64.10 }
64.11
65.1 --- a/src/share/classes/java/awt/geom/QuadCurve2D.java Thu Sep 15 18:53:28 2011 -0700
65.2 +++ b/src/share/classes/java/awt/geom/QuadCurve2D.java Mon Sep 19 19:40:59 2011 -0700
65.3 @@ -1395,7 +1395,7 @@
65.4 return super.clone();
65.5 } catch (CloneNotSupportedException e) {
65.6 // this shouldn't happen, since we are Cloneable
65.7 - throw new InternalError();
65.8 + throw new InternalError(e);
65.9 }
65.10 }
65.11 }
66.1 --- a/src/share/classes/java/awt/geom/RectangularShape.java Thu Sep 15 18:53:28 2011 -0700
66.2 +++ b/src/share/classes/java/awt/geom/RectangularShape.java Mon Sep 19 19:40:59 2011 -0700
66.3 @@ -391,7 +391,7 @@
66.4 return super.clone();
66.5 } catch (CloneNotSupportedException e) {
66.6 // this shouldn't happen, since we are Cloneable
66.7 - throw new InternalError();
66.8 + throw new InternalError(e);
66.9 }
66.10 }
66.11 }
67.1 --- a/src/share/classes/java/awt/image/ImageFilter.java Thu Sep 15 18:53:28 2011 -0700
67.2 +++ b/src/share/classes/java/awt/image/ImageFilter.java Mon Sep 19 19:40:59 2011 -0700
67.3 @@ -252,7 +252,7 @@
67.4 return super.clone();
67.5 } catch (CloneNotSupportedException e) {
67.6 // this shouldn't happen, since we are Cloneable
67.7 - throw new InternalError();
67.8 + throw new InternalError(e);
67.9 }
67.10 }
67.11 }
68.1 --- a/src/share/classes/java/awt/image/Kernel.java Thu Sep 15 18:53:28 2011 -0700
68.2 +++ b/src/share/classes/java/awt/image/Kernel.java Mon Sep 19 19:40:59 2011 -0700
68.3 @@ -147,7 +147,7 @@
68.4 return super.clone();
68.5 } catch (CloneNotSupportedException e) {
68.6 // this shouldn't happen, since we are Cloneable
68.7 - throw new InternalError();
68.8 + throw new InternalError(e);
68.9 }
68.10 }
68.11 }
69.1 --- a/src/share/classes/java/io/ObjectStreamClass.java Thu Sep 15 18:53:28 2011 -0700
69.2 +++ b/src/share/classes/java/io/ObjectStreamClass.java Mon Sep 19 19:40:59 2011 -0700
69.3 @@ -478,7 +478,7 @@
69.4 fieldRefl = getReflector(fields, this);
69.5 } catch (InvalidClassException ex) {
69.6 // field mismatches impossible when matching local fields vs. self
69.7 - throw new InternalError();
69.8 + throw new InternalError(ex);
69.9 }
69.10
69.11 if (deserializeEx == null) {
69.12 @@ -941,7 +941,7 @@
69.13 return cons.newInstance();
69.14 } catch (IllegalAccessException ex) {
69.15 // should not occur, as access checks have been suppressed
69.16 - throw new InternalError();
69.17 + throw new InternalError(ex);
69.18 }
69.19 } else {
69.20 throw new UnsupportedOperationException();
69.21 @@ -969,7 +969,7 @@
69.22 }
69.23 } catch (IllegalAccessException ex) {
69.24 // should not occur, as access checks have been suppressed
69.25 - throw new InternalError();
69.26 + throw new InternalError(ex);
69.27 }
69.28 } else {
69.29 throw new UnsupportedOperationException();
69.30 @@ -1000,7 +1000,7 @@
69.31 }
69.32 } catch (IllegalAccessException ex) {
69.33 // should not occur, as access checks have been suppressed
69.34 - throw new InternalError();
69.35 + throw new InternalError(ex);
69.36 }
69.37 } else {
69.38 throw new UnsupportedOperationException();
69.39 @@ -1028,7 +1028,7 @@
69.40 }
69.41 } catch (IllegalAccessException ex) {
69.42 // should not occur, as access checks have been suppressed
69.43 - throw new InternalError();
69.44 + throw new InternalError(ex);
69.45 }
69.46 } else {
69.47 throw new UnsupportedOperationException();
69.48 @@ -1053,11 +1053,11 @@
69.49 throw (ObjectStreamException) th;
69.50 } else {
69.51 throwMiscException(th);
69.52 - throw new InternalError(); // never reached
69.53 + throw new InternalError(th); // never reached
69.54 }
69.55 } catch (IllegalAccessException ex) {
69.56 // should not occur, as access checks have been suppressed
69.57 - throw new InternalError();
69.58 + throw new InternalError(ex);
69.59 }
69.60 } else {
69.61 throw new UnsupportedOperationException();
69.62 @@ -1082,11 +1082,11 @@
69.63 throw (ObjectStreamException) th;
69.64 } else {
69.65 throwMiscException(th);
69.66 - throw new InternalError(); // never reached
69.67 + throw new InternalError(th); // never reached
69.68 }
69.69 } catch (IllegalAccessException ex) {
69.70 // should not occur, as access checks have been suppressed
69.71 - throw new InternalError();
69.72 + throw new InternalError(ex);
69.73 }
69.74 } else {
69.75 throw new UnsupportedOperationException();
69.76 @@ -1774,7 +1774,7 @@
69.77 }
69.78 return hash;
69.79 } catch (IOException ex) {
69.80 - throw new InternalError();
69.81 + throw new InternalError(ex);
69.82 } catch (NoSuchAlgorithmException ex) {
69.83 throw new SecurityException(ex.getMessage());
69.84 }
70.1 --- a/src/share/classes/java/lang/CharacterName.java Thu Sep 15 18:53:28 2011 -0700
70.2 +++ b/src/share/classes/java/lang/CharacterName.java Mon Sep 19 19:40:59 2011 -0700
70.3 @@ -83,7 +83,7 @@
70.4 dis.readFully(strPool);
70.5 refStrPool = new SoftReference<>(strPool);
70.6 } catch (Exception x) {
70.7 - throw new InternalError(x.getMessage());
70.8 + throw new InternalError(x.getMessage(), x);
70.9 } finally {
70.10 try {
70.11 if (dis != null)
71.1 --- a/src/share/classes/java/lang/Class.java Thu Sep 15 18:53:28 2011 -0700
71.2 +++ b/src/share/classes/java/lang/Class.java Mon Sep 19 19:40:59 2011 -0700
71.3 @@ -974,8 +974,7 @@
71.4 descriptor = (String) enclosingInfo[2];
71.5 assert((name != null && descriptor != null) || name == descriptor);
71.6 } catch (ClassCastException cce) {
71.7 - throw (InternalError)
71.8 - new InternalError("Invalid type in enclosing method information").initCause(cce);
71.9 + throw new InternalError("Invalid type in enclosing method information", cce);
71.10 }
71.11 }
71.12
71.13 @@ -1241,8 +1240,7 @@
71.14 try {
71.15 return getName().substring(enclosingClass.getName().length());
71.16 } catch (IndexOutOfBoundsException ex) {
71.17 - throw (InternalError)
71.18 - new InternalError("Malformed class name").initCause(ex);
71.19 + throw new InternalError("Malformed class name", ex);
71.20 }
71.21 }
71.22
72.1 --- a/src/share/classes/java/lang/invoke/CallSite.java Thu Sep 15 18:53:28 2011 -0700
72.2 +++ b/src/share/classes/java/lang/invoke/CallSite.java Mon Sep 19 19:40:59 2011 -0700
72.3 @@ -27,7 +27,6 @@
72.4
72.5 import sun.invoke.empty.Empty;
72.6 import sun.misc.Unsafe;
72.7 -import static java.lang.invoke.MethodHandleStatics.*;
72.8 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
72.9
72.10 /**
72.11 @@ -244,8 +243,8 @@
72.12 try {
72.13 GET_TARGET = IMPL_LOOKUP.
72.14 findVirtual(CallSite.class, "getTarget", MethodType.methodType(MethodHandle.class));
72.15 - } catch (ReflectiveOperationException ignore) {
72.16 - throw new InternalError();
72.17 + } catch (ReflectiveOperationException e) {
72.18 + throw new InternalError(e);
72.19 }
72.20 }
72.21
73.1 --- a/src/share/classes/java/lang/invoke/Invokers.java Thu Sep 15 18:53:28 2011 -0700
73.2 +++ b/src/share/classes/java/lang/invoke/Invokers.java Mon Sep 19 19:40:59 2011 -0700
73.3 @@ -88,7 +88,7 @@
73.4 try {
73.5 invoker = IMPL_LOOKUP.findVirtual(MethodHandle.class, name, targetType);
73.6 } catch (ReflectiveOperationException ex) {
73.7 - throw new InternalError("JVM cannot find invoker for "+targetType);
73.8 + throw new InternalError("JVM cannot find invoker for "+targetType, ex);
73.9 }
73.10 assert(invokerType(targetType) == invoker.type());
73.11 assert(!invoker.isVarargsCollector());
74.1 --- a/src/share/classes/java/lang/invoke/MemberName.java Thu Sep 15 18:53:28 2011 -0700
74.2 +++ b/src/share/classes/java/lang/invoke/MemberName.java Mon Sep 19 19:40:59 2011 -0700
74.3 @@ -382,7 +382,7 @@
74.4 try {
74.5 return (MemberName) super.clone();
74.6 } catch (CloneNotSupportedException ex) {
74.7 - throw new InternalError();
74.8 + throw new InternalError(ex);
74.9 }
74.10 }
74.11
75.1 --- a/src/share/classes/java/lang/invoke/MethodHandleStatics.java Thu Sep 15 18:53:28 2011 -0700
75.2 +++ b/src/share/classes/java/lang/invoke/MethodHandleStatics.java Mon Sep 19 19:40:59 2011 -0700
75.3 @@ -108,9 +108,7 @@
75.4 return new IllegalArgumentException(message(message, obj, obj2));
75.5 }
75.6 /*non-public*/ static Error uncaughtException(Exception ex) {
75.7 - Error err = new InternalError("uncaught exception");
75.8 - err.initCause(ex);
75.9 - return err;
75.10 + throw new InternalError("uncaught exception", ex);
75.11 }
75.12 private static String message(String message, Object obj) {
75.13 if (obj != null) message = message + ": " + obj;
76.1 --- a/src/share/classes/java/lang/invoke/MethodTypeForm.java Thu Sep 15 18:53:28 2011 -0700
76.2 +++ b/src/share/classes/java/lang/invoke/MethodTypeForm.java Mon Sep 19 19:40:59 2011 -0700
76.3 @@ -461,7 +461,7 @@
76.4 // Trigger adapter creation.
76.5 genericInvoker = InvokeGeneric.generalInvokerOf(erasedType);
76.6 } catch (Exception ex) {
76.7 - Error err = new InternalError("Exception while resolving inexact invoke");
76.8 + Error err = new InternalError("Exception while resolving inexact invoke", ex);
76.9 err.initCause(ex);
76.10 throw err;
76.11 }
77.1 --- a/src/share/classes/java/lang/reflect/Proxy.java Thu Sep 15 18:53:28 2011 -0700
77.2 +++ b/src/share/classes/java/lang/reflect/Proxy.java Mon Sep 19 19:40:59 2011 -0700
77.3 @@ -610,7 +610,7 @@
77.4 IllegalAccessException |
77.5 InstantiationException |
77.6 InvocationTargetException e) {
77.7 - throw new InternalError(e.toString());
77.8 + throw new InternalError(e.toString(), e);
77.9 }
77.10 }
77.11
78.1 --- a/src/share/classes/java/lang/reflect/TypeVariable.java Thu Sep 15 18:53:28 2011 -0700
78.2 +++ b/src/share/classes/java/lang/reflect/TypeVariable.java Mon Sep 19 19:40:59 2011 -0700
78.3 @@ -48,7 +48,7 @@
78.4 *
78.5 * @since 1.5
78.6 */
78.7 -public interface TypeVariable<D extends GenericDeclaration> extends Type {
78.8 +public interface TypeVariable<D extends GenericDeclaration> extends Type, AnnotatedElement {
78.9 /**
78.10 * Returns an array of {@code Type} objects representing the
78.11 * upper bound(s) of this type variable. Note that if no upper bound is
79.1 --- a/src/share/classes/java/math/BigDecimal.java Thu Sep 15 18:53:28 2011 -0700
79.2 +++ b/src/share/classes/java/math/BigDecimal.java Mon Sep 19 19:40:59 2011 -0700
79.3 @@ -215,6 +215,7 @@
79.4 * @author Josh Bloch
79.5 * @author Mike Cowlishaw
79.6 * @author Joseph D. Darcy
79.7 + * @author Sergey V. Kuksenko
79.8 */
79.9 public class BigDecimal extends Number implements Comparable<BigDecimal> {
79.10 /**
79.11 @@ -224,7 +225,7 @@
79.12 * @serial
79.13 * @see #unscaledValue
79.14 */
79.15 - private volatile BigInteger intVal;
79.16 + private final BigInteger intVal;
79.17
79.18 /**
79.19 * The scale of this BigDecimal, as returned by {@link #scale}.
79.20 @@ -232,8 +233,9 @@
79.21 * @serial
79.22 * @see #scale
79.23 */
79.24 - private int scale; // Note: this may have any value, so
79.25 - // calculations must be done in longs
79.26 + private final int scale; // Note: this may have any value, so
79.27 + // calculations must be done in longs
79.28 +
79.29 /**
79.30 * The number of decimal digits in this BigDecimal, or 0 if the
79.31 * number of digits are not known (lookaside information). If
79.32 @@ -256,19 +258,19 @@
79.33 */
79.34 static final long INFLATED = Long.MIN_VALUE;
79.35
79.36 + private static final BigInteger INFLATED_BIGINT = BigInteger.valueOf(INFLATED);
79.37 +
79.38 /**
79.39 * If the absolute value of the significand of this BigDecimal is
79.40 * less than or equal to {@code Long.MAX_VALUE}, the value can be
79.41 * compactly stored in this field and used in computations.
79.42 */
79.43 - private transient long intCompact;
79.44 + private final transient long intCompact;
79.45
79.46 // All 18-digit base ten strings fit into a long; not all 19-digit
79.47 // strings will
79.48 private static final int MAX_COMPACT_DIGITS = 18;
79.49
79.50 - private static final int MAX_BIGINT_BITS = 62;
79.51 -
79.52 /* Appease the serialization gods */
79.53 private static final long serialVersionUID = 6108874887143696463L;
79.54
79.55 @@ -282,17 +284,17 @@
79.56
79.57 // Cache of common small BigDecimal values.
79.58 private static final BigDecimal zeroThroughTen[] = {
79.59 - new BigDecimal(BigInteger.ZERO, 0, 0, 1),
79.60 - new BigDecimal(BigInteger.ONE, 1, 0, 1),
79.61 - new BigDecimal(BigInteger.valueOf(2), 2, 0, 1),
79.62 - new BigDecimal(BigInteger.valueOf(3), 3, 0, 1),
79.63 - new BigDecimal(BigInteger.valueOf(4), 4, 0, 1),
79.64 - new BigDecimal(BigInteger.valueOf(5), 5, 0, 1),
79.65 - new BigDecimal(BigInteger.valueOf(6), 6, 0, 1),
79.66 - new BigDecimal(BigInteger.valueOf(7), 7, 0, 1),
79.67 - new BigDecimal(BigInteger.valueOf(8), 8, 0, 1),
79.68 - new BigDecimal(BigInteger.valueOf(9), 9, 0, 1),
79.69 - new BigDecimal(BigInteger.TEN, 10, 0, 2),
79.70 + new BigDecimal(BigInteger.ZERO, 0, 0, 1),
79.71 + new BigDecimal(BigInteger.ONE, 1, 0, 1),
79.72 + new BigDecimal(BigInteger.valueOf(2), 2, 0, 1),
79.73 + new BigDecimal(BigInteger.valueOf(3), 3, 0, 1),
79.74 + new BigDecimal(BigInteger.valueOf(4), 4, 0, 1),
79.75 + new BigDecimal(BigInteger.valueOf(5), 5, 0, 1),
79.76 + new BigDecimal(BigInteger.valueOf(6), 6, 0, 1),
79.77 + new BigDecimal(BigInteger.valueOf(7), 7, 0, 1),
79.78 + new BigDecimal(BigInteger.valueOf(8), 8, 0, 1),
79.79 + new BigDecimal(BigInteger.valueOf(9), 9, 0, 1),
79.80 + new BigDecimal(BigInteger.TEN, 10, 0, 2),
79.81 };
79.82
79.83 // Cache of zero scaled by 0 - 15
79.84 @@ -378,178 +380,7 @@
79.85 * @since 1.5
79.86 */
79.87 public BigDecimal(char[] in, int offset, int len) {
79.88 - // protect against huge length.
79.89 - if (offset+len > in.length || offset < 0)
79.90 - throw new NumberFormatException();
79.91 - // This is the primary string to BigDecimal constructor; all
79.92 - // incoming strings end up here; it uses explicit (inline)
79.93 - // parsing for speed and generates at most one intermediate
79.94 - // (temporary) object (a char[] array) for non-compact case.
79.95 -
79.96 - // Use locals for all fields values until completion
79.97 - int prec = 0; // record precision value
79.98 - int scl = 0; // record scale value
79.99 - long rs = 0; // the compact value in long
79.100 - BigInteger rb = null; // the inflated value in BigInteger
79.101 -
79.102 - // use array bounds checking to handle too-long, len == 0,
79.103 - // bad offset, etc.
79.104 - try {
79.105 - // handle the sign
79.106 - boolean isneg = false; // assume positive
79.107 - if (in[offset] == '-') {
79.108 - isneg = true; // leading minus means negative
79.109 - offset++;
79.110 - len--;
79.111 - } else if (in[offset] == '+') { // leading + allowed
79.112 - offset++;
79.113 - len--;
79.114 - }
79.115 -
79.116 - // should now be at numeric part of the significand
79.117 - boolean dot = false; // true when there is a '.'
79.118 - int cfirst = offset; // record start of integer
79.119 - long exp = 0; // exponent
79.120 - char c; // current character
79.121 -
79.122 - boolean isCompact = (len <= MAX_COMPACT_DIGITS);
79.123 - // integer significand array & idx is the index to it. The array
79.124 - // is ONLY used when we can't use a compact representation.
79.125 - char coeff[] = isCompact ? null : new char[len];
79.126 - int idx = 0;
79.127 -
79.128 - for (; len > 0; offset++, len--) {
79.129 - c = in[offset];
79.130 - // have digit
79.131 - if ((c >= '0' && c <= '9') || Character.isDigit(c)) {
79.132 - // First compact case, we need not to preserve the character
79.133 - // and we can just compute the value in place.
79.134 - if (isCompact) {
79.135 - int digit = Character.digit(c, 10);
79.136 - if (digit == 0) {
79.137 - if (prec == 0)
79.138 - prec = 1;
79.139 - else if (rs != 0) {
79.140 - rs *= 10;
79.141 - ++prec;
79.142 - } // else digit is a redundant leading zero
79.143 - } else {
79.144 - if (prec != 1 || rs != 0)
79.145 - ++prec; // prec unchanged if preceded by 0s
79.146 - rs = rs * 10 + digit;
79.147 - }
79.148 - } else { // the unscaled value is likely a BigInteger object.
79.149 - if (c == '0' || Character.digit(c, 10) == 0) {
79.150 - if (prec == 0) {
79.151 - coeff[idx] = c;
79.152 - prec = 1;
79.153 - } else if (idx != 0) {
79.154 - coeff[idx++] = c;
79.155 - ++prec;
79.156 - } // else c must be a redundant leading zero
79.157 - } else {
79.158 - if (prec != 1 || idx != 0)
79.159 - ++prec; // prec unchanged if preceded by 0s
79.160 - coeff[idx++] = c;
79.161 - }
79.162 - }
79.163 - if (dot)
79.164 - ++scl;
79.165 - continue;
79.166 - }
79.167 - // have dot
79.168 - if (c == '.') {
79.169 - // have dot
79.170 - if (dot) // two dots
79.171 - throw new NumberFormatException();
79.172 - dot = true;
79.173 - continue;
79.174 - }
79.175 - // exponent expected
79.176 - if ((c != 'e') && (c != 'E'))
79.177 - throw new NumberFormatException();
79.178 - offset++;
79.179 - c = in[offset];
79.180 - len--;
79.181 - boolean negexp = (c == '-');
79.182 - // optional sign
79.183 - if (negexp || c == '+') {
79.184 - offset++;
79.185 - c = in[offset];
79.186 - len--;
79.187 - }
79.188 - if (len <= 0) // no exponent digits
79.189 - throw new NumberFormatException();
79.190 - // skip leading zeros in the exponent
79.191 - while (len > 10 && Character.digit(c, 10) == 0) {
79.192 - offset++;
79.193 - c = in[offset];
79.194 - len--;
79.195 - }
79.196 - if (len > 10) // too many nonzero exponent digits
79.197 - throw new NumberFormatException();
79.198 - // c now holds first digit of exponent
79.199 - for (;; len--) {
79.200 - int v;
79.201 - if (c >= '0' && c <= '9') {
79.202 - v = c - '0';
79.203 - } else {
79.204 - v = Character.digit(c, 10);
79.205 - if (v < 0) // not a digit
79.206 - throw new NumberFormatException();
79.207 - }
79.208 - exp = exp * 10 + v;
79.209 - if (len == 1)
79.210 - break; // that was final character
79.211 - offset++;
79.212 - c = in[offset];
79.213 - }
79.214 - if (negexp) // apply sign
79.215 - exp = -exp;
79.216 - // Next test is required for backwards compatibility
79.217 - if ((int)exp != exp) // overflow
79.218 - throw new NumberFormatException();
79.219 - break; // [saves a test]
79.220 - }
79.221 - // here when no characters left
79.222 - if (prec == 0) // no digits found
79.223 - throw new NumberFormatException();
79.224 -
79.225 - // Adjust scale if exp is not zero.
79.226 - if (exp != 0) { // had significant exponent
79.227 - // Can't call checkScale which relies on proper fields value
79.228 - long adjustedScale = scl - exp;
79.229 - if (adjustedScale > Integer.MAX_VALUE ||
79.230 - adjustedScale < Integer.MIN_VALUE)
79.231 - throw new NumberFormatException("Scale out of range.");
79.232 - scl = (int)adjustedScale;
79.233 - }
79.234 -
79.235 - // Remove leading zeros from precision (digits count)
79.236 - if (isCompact) {
79.237 - rs = isneg ? -rs : rs;
79.238 - } else {
79.239 - char quick[];
79.240 - if (!isneg) {
79.241 - quick = (coeff.length != prec) ?
79.242 - Arrays.copyOf(coeff, prec) : coeff;
79.243 - } else {
79.244 - quick = new char[prec + 1];
79.245 - quick[0] = '-';
79.246 - System.arraycopy(coeff, 0, quick, 1, prec);
79.247 - }
79.248 - rb = new BigInteger(quick);
79.249 - rs = compactValFor(rb);
79.250 - }
79.251 - } catch (ArrayIndexOutOfBoundsException e) {
79.252 - throw new NumberFormatException();
79.253 - } catch (NegativeArraySizeException e) {
79.254 - throw new NumberFormatException();
79.255 - }
79.256 - this.scale = scl;
79.257 - this.precision = prec;
79.258 - this.intCompact = rs;
79.259 - this.intVal = (rs != INFLATED) ? null : rb;
79.260 + this(in,offset,len,MathContext.UNLIMITED);
79.261 }
79.262
79.263 /**
79.264 @@ -576,9 +407,254 @@
79.265 * @since 1.5
79.266 */
79.267 public BigDecimal(char[] in, int offset, int len, MathContext mc) {
79.268 - this(in, offset, len);
79.269 - if (mc.precision > 0)
79.270 - roundThis(mc);
79.271 + // protect against huge length.
79.272 + if (offset + len > in.length || offset < 0)
79.273 + throw new NumberFormatException("Bad offset or len arguments for char[] input.");
79.274 + // This is the primary string to BigDecimal constructor; all
79.275 + // incoming strings end up here; it uses explicit (inline)
79.276 + // parsing for speed and generates at most one intermediate
79.277 + // (temporary) object (a char[] array) for non-compact case.
79.278 +
79.279 + // Use locals for all fields values until completion
79.280 + int prec = 0; // record precision value
79.281 + int scl = 0; // record scale value
79.282 + long rs = 0; // the compact value in long
79.283 + BigInteger rb = null; // the inflated value in BigInteger
79.284 + // use array bounds checking to handle too-long, len == 0,
79.285 + // bad offset, etc.
79.286 + try {
79.287 + // handle the sign
79.288 + boolean isneg = false; // assume positive
79.289 + if (in[offset] == '-') {
79.290 + isneg = true; // leading minus means negative
79.291 + offset++;
79.292 + len--;
79.293 + } else if (in[offset] == '+') { // leading + allowed
79.294 + offset++;
79.295 + len--;
79.296 + }
79.297 +
79.298 + // should now be at numeric part of the significand
79.299 + boolean dot = false; // true when there is a '.'
79.300 + long exp = 0; // exponent
79.301 + char c; // current character
79.302 + boolean isCompact = (len <= MAX_COMPACT_DIGITS);
79.303 + // integer significand array & idx is the index to it. The array
79.304 + // is ONLY used when we can't use a compact representation.
79.305 + int idx = 0;
79.306 + if (isCompact) {
79.307 + // First compact case, we need not to preserve the character
79.308 + // and we can just compute the value in place.
79.309 + for (; len > 0; offset++, len--) {
79.310 + c = in[offset];
79.311 + if ((c == '0')) { // have zero
79.312 + if (prec == 0)
79.313 + prec = 1;
79.314 + else if (rs != 0) {
79.315 + rs *= 10;
79.316 + ++prec;
79.317 + } // else digit is a redundant leading zero
79.318 + if (dot)
79.319 + ++scl;
79.320 + } else if ((c >= '1' && c <= '9')) { // have digit
79.321 + int digit = c - '0';
79.322 + if (prec != 1 || rs != 0)
79.323 + ++prec; // prec unchanged if preceded by 0s
79.324 + rs = rs * 10 + digit;
79.325 + if (dot)
79.326 + ++scl;
79.327 + } else if (c == '.') { // have dot
79.328 + // have dot
79.329 + if (dot) // two dots
79.330 + throw new NumberFormatException();
79.331 + dot = true;
79.332 + } else if (Character.isDigit(c)) { // slow path
79.333 + int digit = Character.digit(c, 10);
79.334 + if (digit == 0) {
79.335 + if (prec == 0)
79.336 + prec = 1;
79.337 + else if (rs != 0) {
79.338 + rs *= 10;
79.339 + ++prec;
79.340 + } // else digit is a redundant leading zero
79.341 + } else {
79.342 + if (prec != 1 || rs != 0)
79.343 + ++prec; // prec unchanged if preceded by 0s
79.344 + rs = rs * 10 + digit;
79.345 + }
79.346 + if (dot)
79.347 + ++scl;
79.348 + } else if ((c == 'e') || (c == 'E')) {
79.349 + exp = parseExp(in, offset, len);
79.350 + // Next test is required for backwards compatibility
79.351 + if ((int) exp != exp) // overflow
79.352 + throw new NumberFormatException();
79.353 + break; // [saves a test]
79.354 + } else {
79.355 + throw new NumberFormatException();
79.356 + }
79.357 + }
79.358 + if (prec == 0) // no digits found
79.359 + throw new NumberFormatException();
79.360 + // Adjust scale if exp is not zero.
79.361 + if (exp != 0) { // had significant exponent
79.362 + scl = adjustScale(scl, exp);
79.363 + }
79.364 + rs = isneg ? -rs : rs;
79.365 + int mcp = mc.precision;
79.366 + int drop = prec - mcp; // prec has range [1, MAX_INT], mcp has range [0, MAX_INT];
79.367 + // therefore, this subtract cannot overflow
79.368 + if (mcp > 0 && drop > 0) { // do rounding
79.369 + while (drop > 0) {
79.370 + scl = checkScaleNonZero((long) scl - drop);
79.371 + rs = divideAndRound(rs, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.372 + prec = longDigitLength(rs);
79.373 + drop = prec - mcp;
79.374 + }
79.375 + }
79.376 + } else {
79.377 + char coeff[] = new char[len];
79.378 + for (; len > 0; offset++, len--) {
79.379 + c = in[offset];
79.380 + // have digit
79.381 + if ((c >= '0' && c <= '9') || Character.isDigit(c)) {
79.382 + // First compact case, we need not to preserve the character
79.383 + // and we can just compute the value in place.
79.384 + if (c == '0' || Character.digit(c, 10) == 0) {
79.385 + if (prec == 0) {
79.386 + coeff[idx] = c;
79.387 + prec = 1;
79.388 + } else if (idx != 0) {
79.389 + coeff[idx++] = c;
79.390 + ++prec;
79.391 + } // else c must be a redundant leading zero
79.392 + } else {
79.393 + if (prec != 1 || idx != 0)
79.394 + ++prec; // prec unchanged if preceded by 0s
79.395 + coeff[idx++] = c;
79.396 + }
79.397 + if (dot)
79.398 + ++scl;
79.399 + continue;
79.400 + }
79.401 + // have dot
79.402 + if (c == '.') {
79.403 + // have dot
79.404 + if (dot) // two dots
79.405 + throw new NumberFormatException();
79.406 + dot = true;
79.407 + continue;
79.408 + }
79.409 + // exponent expected
79.410 + if ((c != 'e') && (c != 'E'))
79.411 + throw new NumberFormatException();
79.412 + exp = parseExp(in, offset, len);
79.413 + // Next test is required for backwards compatibility
79.414 + if ((int) exp != exp) // overflow
79.415 + throw new NumberFormatException();
79.416 + break; // [saves a test]
79.417 + }
79.418 + // here when no characters left
79.419 + if (prec == 0) // no digits found
79.420 + throw new NumberFormatException();
79.421 + // Adjust scale if exp is not zero.
79.422 + if (exp != 0) { // had significant exponent
79.423 + scl = adjustScale(scl, exp);
79.424 + }
79.425 + // Remove leading zeros from precision (digits count)
79.426 + rb = new BigInteger(coeff, isneg ? -1 : 1, prec);
79.427 + rs = compactValFor(rb);
79.428 + int mcp = mc.precision;
79.429 + if (mcp > 0 && (prec > mcp)) {
79.430 + if (rs == INFLATED) {
79.431 + int drop = prec - mcp;
79.432 + while (drop > 0) {
79.433 + scl = checkScaleNonZero((long) scl - drop);
79.434 + rb = divideAndRoundByTenPow(rb, drop, mc.roundingMode.oldMode);
79.435 + rs = compactValFor(rb);
79.436 + if (rs != INFLATED) {
79.437 + prec = longDigitLength(rs);
79.438 + break;
79.439 + }
79.440 + prec = bigDigitLength(rb);
79.441 + drop = prec - mcp;
79.442 + }
79.443 + }
79.444 + if (rs != INFLATED) {
79.445 + int drop = prec - mcp;
79.446 + while (drop > 0) {
79.447 + scl = checkScaleNonZero((long) scl - drop);
79.448 + rs = divideAndRound(rs, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.449 + prec = longDigitLength(rs);
79.450 + drop = prec - mcp;
79.451 + }
79.452 + rb = null;
79.453 + }
79.454 + }
79.455 + }
79.456 + } catch (ArrayIndexOutOfBoundsException e) {
79.457 + throw new NumberFormatException();
79.458 + } catch (NegativeArraySizeException e) {
79.459 + throw new NumberFormatException();
79.460 + }
79.461 + this.scale = scl;
79.462 + this.precision = prec;
79.463 + this.intCompact = rs;
79.464 + this.intVal = rb;
79.465 + }
79.466 +
79.467 + private int adjustScale(int scl, long exp) {
79.468 + long adjustedScale = scl - exp;
79.469 + if (adjustedScale > Integer.MAX_VALUE || adjustedScale < Integer.MIN_VALUE)
79.470 + throw new NumberFormatException("Scale out of range.");
79.471 + scl = (int) adjustedScale;
79.472 + return scl;
79.473 + }
79.474 +
79.475 + /*
79.476 + * parse exponent
79.477 + */
79.478 + private static long parseExp(char[] in, int offset, int len){
79.479 + long exp = 0;
79.480 + offset++;
79.481 + char c = in[offset];
79.482 + len--;
79.483 + boolean negexp = (c == '-');
79.484 + // optional sign
79.485 + if (negexp || c == '+') {
79.486 + offset++;
79.487 + c = in[offset];
79.488 + len--;
79.489 + }
79.490 + if (len <= 0) // no exponent digits
79.491 + throw new NumberFormatException();
79.492 + // skip leading zeros in the exponent
79.493 + while (len > 10 && (c=='0' || (Character.digit(c, 10) == 0))) {
79.494 + offset++;
79.495 + c = in[offset];
79.496 + len--;
79.497 + }
79.498 + if (len > 10) // too many nonzero exponent digits
79.499 + throw new NumberFormatException();
79.500 + // c now holds first digit of exponent
79.501 + for (;; len--) {
79.502 + int v;
79.503 + if (c >= '0' && c <= '9') {
79.504 + v = c - '0';
79.505 + } else {
79.506 + v = Character.digit(c, 10);
79.507 + if (v < 0) // not a digit
79.508 + throw new NumberFormatException();
79.509 + }
79.510 + exp = exp * 10 + v;
79.511 + if (len == 1)
79.512 + break; // that was final character
79.513 + offset++;
79.514 + c = in[offset];
79.515 + }
79.516 + if (negexp) // apply sign
79.517 + exp = -exp;
79.518 + return exp;
79.519 }
79.520
79.521 /**
79.522 @@ -754,9 +830,7 @@
79.523 * @since 1.5
79.524 */
79.525 public BigDecimal(String val, MathContext mc) {
79.526 - this(val.toCharArray(), 0, val.length());
79.527 - if (mc.precision > 0)
79.528 - roundThis(mc);
79.529 + this(val.toCharArray(), 0, val.length(), mc);
79.530 }
79.531
79.532 /**
79.533 @@ -804,49 +878,7 @@
79.534 * @throws NumberFormatException if {@code val} is infinite or NaN.
79.535 */
79.536 public BigDecimal(double val) {
79.537 - if (Double.isInfinite(val) || Double.isNaN(val))
79.538 - throw new NumberFormatException("Infinite or NaN");
79.539 -
79.540 - // Translate the double into sign, exponent and significand, according
79.541 - // to the formulae in JLS, Section 20.10.22.
79.542 - long valBits = Double.doubleToLongBits(val);
79.543 - int sign = ((valBits >> 63)==0 ? 1 : -1);
79.544 - int exponent = (int) ((valBits >> 52) & 0x7ffL);
79.545 - long significand = (exponent==0 ? (valBits & ((1L<<52) - 1)) << 1
79.546 - : (valBits & ((1L<<52) - 1)) | (1L<<52));
79.547 - exponent -= 1075;
79.548 - // At this point, val == sign * significand * 2**exponent.
79.549 -
79.550 - /*
79.551 - * Special case zero to supress nonterminating normalization
79.552 - * and bogus scale calculation.
79.553 - */
79.554 - if (significand == 0) {
79.555 - intVal = BigInteger.ZERO;
79.556 - intCompact = 0;
79.557 - precision = 1;
79.558 - return;
79.559 - }
79.560 -
79.561 - // Normalize
79.562 - while((significand & 1) == 0) { // i.e., significand is even
79.563 - significand >>= 1;
79.564 - exponent++;
79.565 - }
79.566 -
79.567 - // Calculate intVal and scale
79.568 - long s = sign * significand;
79.569 - BigInteger b;
79.570 - if (exponent < 0) {
79.571 - b = BigInteger.valueOf(5).pow(-exponent).multiply(s);
79.572 - scale = -exponent;
79.573 - } else if (exponent > 0) {
79.574 - b = BigInteger.valueOf(2).pow(exponent).multiply(s);
79.575 - } else {
79.576 - b = BigInteger.valueOf(s);
79.577 - }
79.578 - intCompact = compactValFor(b);
79.579 - intVal = (intCompact != INFLATED) ? null : b;
79.580 + this(val,MathContext.UNLIMITED);
79.581 }
79.582
79.583 /**
79.584 @@ -868,9 +900,85 @@
79.585 * @since 1.5
79.586 */
79.587 public BigDecimal(double val, MathContext mc) {
79.588 - this(val);
79.589 - if (mc.precision > 0)
79.590 - roundThis(mc);
79.591 + if (Double.isInfinite(val) || Double.isNaN(val))
79.592 + throw new NumberFormatException("Infinite or NaN");
79.593 + // Translate the double into sign, exponent and significand, according
79.594 + // to the formulae in JLS, Section 20.10.22.
79.595 + long valBits = Double.doubleToLongBits(val);
79.596 + int sign = ((valBits >> 63) == 0 ? 1 : -1);
79.597 + int exponent = (int) ((valBits >> 52) & 0x7ffL);
79.598 + long significand = (exponent == 0
79.599 + ? (valBits & ((1L << 52) - 1)) << 1
79.600 + : (valBits & ((1L << 52) - 1)) | (1L << 52));
79.601 + exponent -= 1075;
79.602 + // At this point, val == sign * significand * 2**exponent.
79.603 +
79.604 + /*
79.605 + * Special case zero to supress nonterminating normalization and bogus
79.606 + * scale calculation.
79.607 + */
79.608 + if (significand == 0) {
79.609 + this.intVal = BigInteger.ZERO;
79.610 + this.scale = 0;
79.611 + this.intCompact = 0;
79.612 + this.precision = 1;
79.613 + return;
79.614 + }
79.615 + // Normalize
79.616 + while ((significand & 1) == 0) { // i.e., significand is even
79.617 + significand >>= 1;
79.618 + exponent++;
79.619 + }
79.620 + int scale = 0;
79.621 + // Calculate intVal and scale
79.622 + BigInteger intVal;
79.623 + long compactVal = sign * significand;
79.624 + if (exponent == 0) {
79.625 + intVal = (compactVal == INFLATED) ? INFLATED_BIGINT : null;
79.626 + } else {
79.627 + if (exponent < 0) {
79.628 + intVal = BigInteger.valueOf(5).pow(-exponent).multiply(compactVal);
79.629 + scale = -exponent;
79.630 + } else { // (exponent > 0)
79.631 + intVal = BigInteger.valueOf(2).pow(exponent).multiply(compactVal);
79.632 + }
79.633 + compactVal = compactValFor(intVal);
79.634 + }
79.635 + int prec = 0;
79.636 + int mcp = mc.precision;
79.637 + if (mcp > 0) { // do rounding
79.638 + int mode = mc.roundingMode.oldMode;
79.639 + int drop;
79.640 + if (compactVal == INFLATED) {
79.641 + prec = bigDigitLength(intVal);
79.642 + drop = prec - mcp;
79.643 + while (drop > 0) {
79.644 + scale = checkScaleNonZero((long) scale - drop);
79.645 + intVal = divideAndRoundByTenPow(intVal, drop, mode);
79.646 + compactVal = compactValFor(intVal);
79.647 + if (compactVal != INFLATED) {
79.648 + break;
79.649 + }
79.650 + prec = bigDigitLength(intVal);
79.651 + drop = prec - mcp;
79.652 + }
79.653 + }
79.654 + if (compactVal != INFLATED) {
79.655 + prec = longDigitLength(compactVal);
79.656 + drop = prec - mcp;
79.657 + while (drop > 0) {
79.658 + scale = checkScaleNonZero((long) scale - drop);
79.659 + compactVal = divideAndRound(compactVal, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.660 + prec = longDigitLength(compactVal);
79.661 + drop = prec - mcp;
79.662 + }
79.663 + intVal = null;
79.664 + }
79.665 + }
79.666 + this.intVal = intVal;
79.667 + this.intCompact = compactVal;
79.668 + this.scale = scale;
79.669 + this.precision = prec;
79.670 }
79.671
79.672 /**
79.673 @@ -881,8 +989,9 @@
79.674 * {@code BigDecimal}.
79.675 */
79.676 public BigDecimal(BigInteger val) {
79.677 + scale = 0;
79.678 + intVal = val;
79.679 intCompact = compactValFor(val);
79.680 - intVal = (intCompact != INFLATED) ? null : val;
79.681 }
79.682
79.683 /**
79.684 @@ -898,9 +1007,7 @@
79.685 * @since 1.5
79.686 */
79.687 public BigDecimal(BigInteger val, MathContext mc) {
79.688 - this(val);
79.689 - if (mc.precision > 0)
79.690 - roundThis(mc);
79.691 + this(val,0,mc);
79.692 }
79.693
79.694 /**
79.695 @@ -914,7 +1021,8 @@
79.696 */
79.697 public BigDecimal(BigInteger unscaledVal, int scale) {
79.698 // Negative scales are now allowed
79.699 - this(unscaledVal);
79.700 + this.intVal = unscaledVal;
79.701 + this.intCompact = compactValFor(unscaledVal);
79.702 this.scale = scale;
79.703 }
79.704
79.705 @@ -934,10 +1042,41 @@
79.706 * @since 1.5
79.707 */
79.708 public BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) {
79.709 - this(unscaledVal);
79.710 + long compactVal = compactValFor(unscaledVal);
79.711 + int mcp = mc.precision;
79.712 + int prec = 0;
79.713 + if (mcp > 0) { // do rounding
79.714 + int mode = mc.roundingMode.oldMode;
79.715 + if (compactVal == INFLATED) {
79.716 + prec = bigDigitLength(unscaledVal);
79.717 + int drop = prec - mcp;
79.718 + while (drop > 0) {
79.719 + scale = checkScaleNonZero((long) scale - drop);
79.720 + unscaledVal = divideAndRoundByTenPow(unscaledVal, drop, mode);
79.721 + compactVal = compactValFor(unscaledVal);
79.722 + if (compactVal != INFLATED) {
79.723 + break;
79.724 + }
79.725 + prec = bigDigitLength(unscaledVal);
79.726 + drop = prec - mcp;
79.727 + }
79.728 + }
79.729 + if (compactVal != INFLATED) {
79.730 + prec = longDigitLength(compactVal);
79.731 + int drop = prec - mcp; // drop can't be more than 18
79.732 + while (drop > 0) {
79.733 + scale = checkScaleNonZero((long) scale - drop);
79.734 + compactVal = divideAndRound(compactVal, LONG_TEN_POWERS_TABLE[drop], mode);
79.735 + prec = longDigitLength(compactVal);
79.736 + drop = prec - mcp;
79.737 + }
79.738 + unscaledVal = null;
79.739 + }
79.740 + }
79.741 + this.intVal = unscaledVal;
79.742 + this.intCompact = compactVal;
79.743 this.scale = scale;
79.744 - if (mc.precision > 0)
79.745 - roundThis(mc);
79.746 + this.precision = prec;
79.747 }
79.748
79.749 /**
79.750 @@ -949,7 +1088,9 @@
79.751 * @since 1.5
79.752 */
79.753 public BigDecimal(int val) {
79.754 - intCompact = val;
79.755 + this.intCompact = val;
79.756 + this.scale = 0;
79.757 + this.intVal = null;
79.758 }
79.759
79.760 /**
79.761 @@ -964,9 +1105,24 @@
79.762 * @since 1.5
79.763 */
79.764 public BigDecimal(int val, MathContext mc) {
79.765 - intCompact = val;
79.766 - if (mc.precision > 0)
79.767 - roundThis(mc);
79.768 + int mcp = mc.precision;
79.769 + long compactVal = val;
79.770 + int scale = 0;
79.771 + int prec = 0;
79.772 + if (mcp > 0) { // do rounding
79.773 + prec = longDigitLength(compactVal);
79.774 + int drop = prec - mcp; // drop can't be more than 18
79.775 + while (drop > 0) {
79.776 + scale = checkScaleNonZero((long) scale - drop);
79.777 + compactVal = divideAndRound(compactVal, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.778 + prec = longDigitLength(compactVal);
79.779 + drop = prec - mcp;
79.780 + }
79.781 + }
79.782 + this.intVal = null;
79.783 + this.intCompact = compactVal;
79.784 + this.scale = scale;
79.785 + this.precision = prec;
79.786 }
79.787
79.788 /**
79.789 @@ -978,7 +1134,8 @@
79.790 */
79.791 public BigDecimal(long val) {
79.792 this.intCompact = val;
79.793 - this.intVal = (val == INFLATED) ? BigInteger.valueOf(val) : null;
79.794 + this.intVal = (val == INFLATED) ? INFLATED_BIGINT : null;
79.795 + this.scale = 0;
79.796 }
79.797
79.798 /**
79.799 @@ -993,9 +1150,42 @@
79.800 * @since 1.5
79.801 */
79.802 public BigDecimal(long val, MathContext mc) {
79.803 - this(val);
79.804 - if (mc.precision > 0)
79.805 - roundThis(mc);
79.806 + int mcp = mc.precision;
79.807 + int mode = mc.roundingMode.oldMode;
79.808 + int prec = 0;
79.809 + int scale = 0;
79.810 + BigInteger intVal = (val == INFLATED) ? INFLATED_BIGINT : null;
79.811 + if (mcp > 0) { // do rounding
79.812 + if (val == INFLATED) {
79.813 + prec = 19;
79.814 + int drop = prec - mcp;
79.815 + while (drop > 0) {
79.816 + scale = checkScaleNonZero((long) scale - drop);
79.817 + intVal = divideAndRoundByTenPow(intVal, drop, mode);
79.818 + val = compactValFor(intVal);
79.819 + if (val != INFLATED) {
79.820 + break;
79.821 + }
79.822 + prec = bigDigitLength(intVal);
79.823 + drop = prec - mcp;
79.824 + }
79.825 + }
79.826 + if (val != INFLATED) {
79.827 + prec = longDigitLength(val);
79.828 + int drop = prec - mcp;
79.829 + while (drop > 0) {
79.830 + scale = checkScaleNonZero((long) scale - drop);
79.831 + val = divideAndRound(val, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.832 + prec = longDigitLength(val);
79.833 + drop = prec - mcp;
79.834 + }
79.835 + intVal = null;
79.836 + }
79.837 + }
79.838 + this.intVal = intVal;
79.839 + this.intCompact = val;
79.840 + this.scale = scale;
79.841 + this.precision = prec;
79.842 }
79.843
79.844 // Static Factory Methods
79.845 @@ -1016,13 +1206,10 @@
79.846 if (scale == 0)
79.847 return valueOf(unscaledVal);
79.848 else if (unscaledVal == 0) {
79.849 - if (scale > 0 && scale < ZERO_SCALED_BY.length)
79.850 - return ZERO_SCALED_BY[scale];
79.851 - else
79.852 - return new BigDecimal(BigInteger.ZERO, 0, scale, 1);
79.853 + return zeroValueOf(scale);
79.854 }
79.855 return new BigDecimal(unscaledVal == INFLATED ?
79.856 - BigInteger.valueOf(unscaledVal) : null,
79.857 + INFLATED_BIGINT : null,
79.858 unscaledVal, scale, 0);
79.859 }
79.860
79.861 @@ -1041,7 +1228,34 @@
79.862 return zeroThroughTen[(int)val];
79.863 else if (val != INFLATED)
79.864 return new BigDecimal(null, val, 0, 0);
79.865 - return new BigDecimal(BigInteger.valueOf(val), val, 0, 0);
79.866 + return new BigDecimal(INFLATED_BIGINT, val, 0, 0);
79.867 + }
79.868 +
79.869 + static BigDecimal valueOf(long unscaledVal, int scale, int prec) {
79.870 + if (scale == 0 && unscaledVal >= 0 && unscaledVal < zeroThroughTen.length) {
79.871 + return zeroThroughTen[(int) unscaledVal];
79.872 + } else if (unscaledVal == 0) {
79.873 + return zeroValueOf(scale);
79.874 + }
79.875 + return new BigDecimal(unscaledVal == INFLATED ? INFLATED_BIGINT : null,
79.876 + unscaledVal, scale, prec);
79.877 + }
79.878 +
79.879 + static BigDecimal valueOf(BigInteger intVal, int scale, int prec) {
79.880 + long val = compactValFor(intVal);
79.881 + if (val == 0) {
79.882 + return zeroValueOf(scale);
79.883 + } else if (scale == 0 && val >= 0 && val < zeroThroughTen.length) {
79.884 + return zeroThroughTen[(int) val];
79.885 + }
79.886 + return new BigDecimal(intVal, val, scale, prec);
79.887 + }
79.888 +
79.889 + static BigDecimal zeroValueOf(int scale) {
79.890 + if (scale >= 0 && scale < ZERO_SCALED_BY.length)
79.891 + return ZERO_SCALED_BY[scale];
79.892 + else
79.893 + return new BigDecimal(BigInteger.ZERO, 0, scale, 1);
79.894 }
79.895
79.896 /**
79.897 @@ -1079,42 +1293,19 @@
79.898 * @return {@code this + augend}
79.899 */
79.900 public BigDecimal add(BigDecimal augend) {
79.901 - long xs = this.intCompact;
79.902 - long ys = augend.intCompact;
79.903 - BigInteger fst = (xs != INFLATED) ? null : this.intVal;
79.904 - BigInteger snd = (ys != INFLATED) ? null : augend.intVal;
79.905 - int rscale = this.scale;
79.906 -
79.907 - long sdiff = (long)rscale - augend.scale;
79.908 - if (sdiff != 0) {
79.909 - if (sdiff < 0) {
79.910 - int raise = checkScale(-sdiff);
79.911 - rscale = augend.scale;
79.912 - if (xs == INFLATED ||
79.913 - (xs = longMultiplyPowerTen(xs, raise)) == INFLATED)
79.914 - fst = bigMultiplyPowerTen(raise);
79.915 + if (this.intCompact != INFLATED) {
79.916 + if ((augend.intCompact != INFLATED)) {
79.917 + return add(this.intCompact, this.scale, augend.intCompact, augend.scale);
79.918 } else {
79.919 - int raise = augend.checkScale(sdiff);
79.920 - if (ys == INFLATED ||
79.921 - (ys = longMultiplyPowerTen(ys, raise)) == INFLATED)
79.922 - snd = augend.bigMultiplyPowerTen(raise);
79.923 + return add(this.intCompact, this.scale, augend.intVal, augend.scale);
79.924 + }
79.925 + } else {
79.926 + if ((augend.intCompact != INFLATED)) {
79.927 + return add(augend.intCompact, augend.scale, this.intVal, this.scale);
79.928 + } else {
79.929 + return add(this.intVal, this.scale, augend.intVal, augend.scale);
79.930 }
79.931 }
79.932 - if (xs != INFLATED && ys != INFLATED) {
79.933 - long sum = xs + ys;
79.934 - // See "Hacker's Delight" section 2-12 for explanation of
79.935 - // the overflow test.
79.936 - if ( (((sum ^ xs) & (sum ^ ys))) >= 0L) // not overflowed
79.937 - return BigDecimal.valueOf(sum, rscale);
79.938 - }
79.939 - if (fst == null)
79.940 - fst = BigInteger.valueOf(xs);
79.941 - if (snd == null)
79.942 - snd = BigInteger.valueOf(ys);
79.943 - BigInteger sum = fst.add(snd);
79.944 - return (fst.signum == snd.signum) ?
79.945 - new BigDecimal(sum, INFLATED, rscale, 0) :
79.946 - new BigDecimal(sum, rscale);
79.947 }
79.948
79.949 /**
79.950 @@ -1136,10 +1327,6 @@
79.951 return add(augend);
79.952 BigDecimal lhs = this;
79.953
79.954 - // Could optimize if values are compact
79.955 - this.inflate();
79.956 - augend.inflate();
79.957 -
79.958 // If either number is zero then the other number, rounded and
79.959 // scaled if necessary, is used as the result.
79.960 {
79.961 @@ -1150,20 +1337,14 @@
79.962 int preferredScale = Math.max(lhs.scale(), augend.scale());
79.963 BigDecimal result;
79.964
79.965 - // Could use a factory for zero instead of a new object
79.966 if (lhsIsZero && augendIsZero)
79.967 - return new BigDecimal(BigInteger.ZERO, 0, preferredScale, 0);
79.968 -
79.969 + return zeroValueOf(preferredScale);
79.970 result = lhsIsZero ? doRound(augend, mc) : doRound(lhs, mc);
79.971
79.972 if (result.scale() == preferredScale)
79.973 return result;
79.974 else if (result.scale() > preferredScale) {
79.975 - BigDecimal scaledResult =
79.976 - new BigDecimal(result.intVal, result.intCompact,
79.977 - result.scale, 0);
79.978 - scaledResult.stripZerosToMatchScale(preferredScale);
79.979 - return scaledResult;
79.980 + return stripZerosToMatchScale(result.intVal, result.intCompact, result.scale, preferredScale);
79.981 } else { // result.scale < preferredScale
79.982 int precisionDiff = mc.precision - result.precision();
79.983 int scaleDiff = preferredScale - result.scale();
79.984 @@ -1176,17 +1357,14 @@
79.985 }
79.986 }
79.987
79.988 - long padding = (long)lhs.scale - augend.scale;
79.989 - if (padding != 0) { // scales differ; alignment needed
79.990 + long padding = (long) lhs.scale - augend.scale;
79.991 + if (padding != 0) { // scales differ; alignment needed
79.992 BigDecimal arg[] = preAlign(lhs, augend, padding, mc);
79.993 matchScale(arg);
79.994 - lhs = arg[0];
79.995 + lhs = arg[0];
79.996 augend = arg[1];
79.997 }
79.998 -
79.999 - BigDecimal d = new BigDecimal(lhs.inflate().add(augend.inflate()),
79.1000 - lhs.scale);
79.1001 - return doRound(d, mc);
79.1002 + return doRound(lhs.inflated().add(augend.inflated()), lhs.scale, mc);
79.1003 }
79.1004
79.1005 /**
79.1006 @@ -1211,27 +1389,26 @@
79.1007 * that the number of digits of the smaller operand could be
79.1008 * reduced even though the significands partially overlapped.
79.1009 */
79.1010 - private BigDecimal[] preAlign(BigDecimal lhs, BigDecimal augend,
79.1011 - long padding, MathContext mc) {
79.1012 + private BigDecimal[] preAlign(BigDecimal lhs, BigDecimal augend, long padding, MathContext mc) {
79.1013 assert padding != 0;
79.1014 BigDecimal big;
79.1015 BigDecimal small;
79.1016
79.1017 - if (padding < 0) { // lhs is big; augend is small
79.1018 - big = lhs;
79.1019 + if (padding < 0) { // lhs is big; augend is small
79.1020 + big = lhs;
79.1021 small = augend;
79.1022 - } else { // lhs is small; augend is big
79.1023 - big = augend;
79.1024 + } else { // lhs is small; augend is big
79.1025 + big = augend;
79.1026 small = lhs;
79.1027 }
79.1028
79.1029 /*
79.1030 - * This is the estimated scale of an ulp of the result; it
79.1031 - * assumes that the result doesn't have a carry-out on a true
79.1032 - * add (e.g. 999 + 1 => 1000) or any subtractive cancellation
79.1033 - * on borrowing (e.g. 100 - 1.2 => 98.8)
79.1034 + * This is the estimated scale of an ulp of the result; it assumes that
79.1035 + * the result doesn't have a carry-out on a true add (e.g. 999 + 1 =>
79.1036 + * 1000) or any subtractive cancellation on borrowing (e.g. 100 - 1.2 =>
79.1037 + * 98.8)
79.1038 */
79.1039 - long estResultUlpScale = (long)big.scale - big.precision() + mc.precision;
79.1040 + long estResultUlpScale = (long) big.scale - big.precision() + mc.precision;
79.1041
79.1042 /*
79.1043 * The low-order digit position of big is big.scale(). This
79.1044 @@ -1242,11 +1419,10 @@
79.1045 * disjoint *and* the digit positions of small should not be
79.1046 * directly visible in the result.
79.1047 */
79.1048 - long smallHighDigitPos = (long)small.scale - small.precision() + 1;
79.1049 - if (smallHighDigitPos > big.scale + 2 && // big and small disjoint
79.1050 + long smallHighDigitPos = (long) small.scale - small.precision() + 1;
79.1051 + if (smallHighDigitPos > big.scale + 2 && // big and small disjoint
79.1052 smallHighDigitPos > estResultUlpScale + 2) { // small digits not visible
79.1053 - small = BigDecimal.valueOf(small.signum(),
79.1054 - this.checkScale(Math.max(big.scale, estResultUlpScale) + 3));
79.1055 + small = BigDecimal.valueOf(small.signum(), this.checkScale(Math.max(big.scale, estResultUlpScale) + 3));
79.1056 }
79.1057
79.1058 // Since addition is symmetric, preserving input order in
79.1059 @@ -1264,7 +1440,22 @@
79.1060 * @return {@code this - subtrahend}
79.1061 */
79.1062 public BigDecimal subtract(BigDecimal subtrahend) {
79.1063 - return add(subtrahend.negate());
79.1064 + if (this.intCompact != INFLATED) {
79.1065 + if ((subtrahend.intCompact != INFLATED)) {
79.1066 + return add(this.intCompact, this.scale, -subtrahend.intCompact, subtrahend.scale);
79.1067 + } else {
79.1068 + return add(this.intCompact, this.scale, subtrahend.intVal.negate(), subtrahend.scale);
79.1069 + }
79.1070 + } else {
79.1071 + if ((subtrahend.intCompact != INFLATED)) {
79.1072 + // Pair of subtrahend values given before pair of
79.1073 + // values from this BigDecimal to avoid need for
79.1074 + // method overloading on the specialized add method
79.1075 + return add(-subtrahend.intCompact, subtrahend.scale, this.intVal, this.scale);
79.1076 + } else {
79.1077 + return add(this.intVal, this.scale, subtrahend.intVal.negate(), subtrahend.scale);
79.1078 + }
79.1079 + }
79.1080 }
79.1081
79.1082 /**
79.1083 @@ -1282,11 +1473,10 @@
79.1084 * @since 1.5
79.1085 */
79.1086 public BigDecimal subtract(BigDecimal subtrahend, MathContext mc) {
79.1087 - BigDecimal nsubtrahend = subtrahend.negate();
79.1088 if (mc.precision == 0)
79.1089 - return add(nsubtrahend);
79.1090 + return subtract(subtrahend);
79.1091 // share the special rounding code in add()
79.1092 - return add(nsubtrahend, mc);
79.1093 + return add(subtrahend.negate(), mc);
79.1094 }
79.1095
79.1096 /**
79.1097 @@ -1298,37 +1488,20 @@
79.1098 * @return {@code this * multiplicand}
79.1099 */
79.1100 public BigDecimal multiply(BigDecimal multiplicand) {
79.1101 - long x = this.intCompact;
79.1102 - long y = multiplicand.intCompact;
79.1103 - int productScale = checkScale((long)scale + multiplicand.scale);
79.1104 -
79.1105 - // Might be able to do a more clever check incorporating the
79.1106 - // inflated check into the overflow computation.
79.1107 - if (x != INFLATED && y != INFLATED) {
79.1108 - /*
79.1109 - * If the product is not an overflowed value, continue
79.1110 - * to use the compact representation. if either of x or y
79.1111 - * is INFLATED, the product should also be regarded as
79.1112 - * an overflow. Before using the overflow test suggested in
79.1113 - * "Hacker's Delight" section 2-12, we perform quick checks
79.1114 - * using the precision information to see whether the overflow
79.1115 - * would occur since division is expensive on most CPUs.
79.1116 - */
79.1117 - long product = x * y;
79.1118 - long prec = this.precision() + multiplicand.precision();
79.1119 - if (prec < 19 || (prec < 21 && (y == 0 || product / y == x)))
79.1120 - return BigDecimal.valueOf(product, productScale);
79.1121 - return new BigDecimal(BigInteger.valueOf(x).multiply(y), INFLATED,
79.1122 - productScale, 0);
79.1123 + int productScale = checkScale((long) scale + multiplicand.scale);
79.1124 + if (this.intCompact != INFLATED) {
79.1125 + if ((multiplicand.intCompact != INFLATED)) {
79.1126 + return multiply(this.intCompact, multiplicand.intCompact, productScale);
79.1127 + } else {
79.1128 + return multiply(this.intCompact, multiplicand.intVal, productScale);
79.1129 + }
79.1130 + } else {
79.1131 + if ((multiplicand.intCompact != INFLATED)) {
79.1132 + return multiply(multiplicand.intCompact, this.intVal, productScale);
79.1133 + } else {
79.1134 + return multiply(this.intVal, multiplicand.intVal, productScale);
79.1135 + }
79.1136 }
79.1137 - BigInteger rb;
79.1138 - if (x == INFLATED && y == INFLATED)
79.1139 - rb = this.intVal.multiply(multiplicand.intVal);
79.1140 - else if (x != INFLATED)
79.1141 - rb = multiplicand.intVal.multiply(x);
79.1142 - else
79.1143 - rb = this.intVal.multiply(y);
79.1144 - return new BigDecimal(rb, INFLATED, productScale, 0);
79.1145 }
79.1146
79.1147 /**
79.1148 @@ -1345,7 +1518,20 @@
79.1149 public BigDecimal multiply(BigDecimal multiplicand, MathContext mc) {
79.1150 if (mc.precision == 0)
79.1151 return multiply(multiplicand);
79.1152 - return doRound(this.multiply(multiplicand), mc);
79.1153 + int productScale = checkScale((long) scale + multiplicand.scale);
79.1154 + if (this.intCompact != INFLATED) {
79.1155 + if ((multiplicand.intCompact != INFLATED)) {
79.1156 + return multiplyAndRound(this.intCompact, multiplicand.intCompact, productScale, mc);
79.1157 + } else {
79.1158 + return multiplyAndRound(this.intCompact, multiplicand.intVal, productScale, mc);
79.1159 + }
79.1160 + } else {
79.1161 + if ((multiplicand.intCompact != INFLATED)) {
79.1162 + return multiplyAndRound(multiplicand.intCompact, this.intVal, productScale, mc);
79.1163 + } else {
79.1164 + return multiplyAndRound(this.intVal, multiplicand.intVal, productScale, mc);
79.1165 + }
79.1166 + }
79.1167 }
79.1168
79.1169 /**
79.1170 @@ -1377,120 +1563,21 @@
79.1171 * @see #ROUND_UNNECESSARY
79.1172 */
79.1173 public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode) {
79.1174 - /*
79.1175 - * IMPLEMENTATION NOTE: This method *must* return a new object
79.1176 - * since divideAndRound uses divide to generate a value whose
79.1177 - * scale is then modified.
79.1178 - */
79.1179 if (roundingMode < ROUND_UP || roundingMode > ROUND_UNNECESSARY)
79.1180 throw new IllegalArgumentException("Invalid rounding mode");
79.1181 - /*
79.1182 - * Rescale dividend or divisor (whichever can be "upscaled" to
79.1183 - * produce correctly scaled quotient).
79.1184 - * Take care to detect out-of-range scales
79.1185 - */
79.1186 - BigDecimal dividend = this;
79.1187 - if (checkScale((long)scale + divisor.scale) > this.scale)
79.1188 - dividend = this.setScale(scale + divisor.scale, ROUND_UNNECESSARY);
79.1189 - else
79.1190 - divisor = divisor.setScale(checkScale((long)this.scale - scale),
79.1191 - ROUND_UNNECESSARY);
79.1192 - return divideAndRound(dividend.intCompact, dividend.intVal,
79.1193 - divisor.intCompact, divisor.intVal,
79.1194 - scale, roundingMode, scale);
79.1195 - }
79.1196 -
79.1197 - /**
79.1198 - * Internally used for division operation. The dividend and divisor are
79.1199 - * passed both in {@code long} format and {@code BigInteger} format. The
79.1200 - * returned {@code BigDecimal} object is the quotient whose scale is set to
79.1201 - * the passed in scale. If the remainder is not zero, it will be rounded
79.1202 - * based on the passed in roundingMode. Also, if the remainder is zero and
79.1203 - * the last parameter, i.e. preferredScale is NOT equal to scale, the
79.1204 - * trailing zeros of the result is stripped to match the preferredScale.
79.1205 - */
79.1206 - private static BigDecimal divideAndRound(long ldividend, BigInteger bdividend,
79.1207 - long ldivisor, BigInteger bdivisor,
79.1208 - int scale, int roundingMode,
79.1209 - int preferredScale) {
79.1210 - boolean isRemainderZero; // record remainder is zero or not
79.1211 - int qsign; // quotient sign
79.1212 - long q = 0, r = 0; // store quotient & remainder in long
79.1213 - MutableBigInteger mq = null; // store quotient
79.1214 - MutableBigInteger mr = null; // store remainder
79.1215 - MutableBigInteger mdivisor = null;
79.1216 - boolean isLongDivision = (ldividend != INFLATED && ldivisor != INFLATED);
79.1217 - if (isLongDivision) {
79.1218 - q = ldividend / ldivisor;
79.1219 - if (roundingMode == ROUND_DOWN && scale == preferredScale)
79.1220 - return new BigDecimal(null, q, scale, 0);
79.1221 - r = ldividend % ldivisor;
79.1222 - isRemainderZero = (r == 0);
79.1223 - qsign = ((ldividend < 0) == (ldivisor < 0)) ? 1 : -1;
79.1224 + if (this.intCompact != INFLATED) {
79.1225 + if ((divisor.intCompact != INFLATED)) {
79.1226 + return divide(this.intCompact, this.scale, divisor.intCompact, divisor.scale, scale, roundingMode);
79.1227 + } else {
79.1228 + return divide(this.intCompact, this.scale, divisor.intVal, divisor.scale, scale, roundingMode);
79.1229 + }
79.1230 } else {
79.1231 - if (bdividend == null)
79.1232 - bdividend = BigInteger.valueOf(ldividend);
79.1233 - // Descend into mutables for faster remainder checks
79.1234 - MutableBigInteger mdividend = new MutableBigInteger(bdividend.mag);
79.1235 - mq = new MutableBigInteger();
79.1236 - if (ldivisor != INFLATED) {
79.1237 - r = mdividend.divide(ldivisor, mq);
79.1238 - isRemainderZero = (r == 0);
79.1239 - qsign = (ldivisor < 0) ? -bdividend.signum : bdividend.signum;
79.1240 + if ((divisor.intCompact != INFLATED)) {
79.1241 + return divide(this.intVal, this.scale, divisor.intCompact, divisor.scale, scale, roundingMode);
79.1242 } else {
79.1243 - mdivisor = new MutableBigInteger(bdivisor.mag);
79.1244 - mr = mdividend.divide(mdivisor, mq);
79.1245 - isRemainderZero = mr.isZero();
79.1246 - qsign = (bdividend.signum != bdivisor.signum) ? -1 : 1;
79.1247 + return divide(this.intVal, this.scale, divisor.intVal, divisor.scale, scale, roundingMode);
79.1248 }
79.1249 }
79.1250 - boolean increment = false;
79.1251 - if (!isRemainderZero) {
79.1252 - int cmpFracHalf;
79.1253 - /* Round as appropriate */
79.1254 - if (roundingMode == ROUND_UNNECESSARY) { // Rounding prohibited
79.1255 - throw new ArithmeticException("Rounding necessary");
79.1256 - } else if (roundingMode == ROUND_UP) { // Away from zero
79.1257 - increment = true;
79.1258 - } else if (roundingMode == ROUND_DOWN) { // Towards zero
79.1259 - increment = false;
79.1260 - } else if (roundingMode == ROUND_CEILING) { // Towards +infinity
79.1261 - increment = (qsign > 0);
79.1262 - } else if (roundingMode == ROUND_FLOOR) { // Towards -infinity
79.1263 - increment = (qsign < 0);
79.1264 - } else {
79.1265 - if (isLongDivision || ldivisor != INFLATED) {
79.1266 - if (r <= HALF_LONG_MIN_VALUE || r > HALF_LONG_MAX_VALUE) {
79.1267 - cmpFracHalf = 1; // 2 * r can't fit into long
79.1268 - } else {
79.1269 - cmpFracHalf = longCompareMagnitude(2 * r, ldivisor);
79.1270 - }
79.1271 - } else {
79.1272 - cmpFracHalf = mr.compareHalf(mdivisor);
79.1273 - }
79.1274 - if (cmpFracHalf < 0)
79.1275 - increment = false; // We're closer to higher digit
79.1276 - else if (cmpFracHalf > 0) // We're closer to lower digit
79.1277 - increment = true;
79.1278 - else if (roundingMode == ROUND_HALF_UP)
79.1279 - increment = true;
79.1280 - else if (roundingMode == ROUND_HALF_DOWN)
79.1281 - increment = false;
79.1282 - else // roundingMode == ROUND_HALF_EVEN, true iff quotient is odd
79.1283 - increment = isLongDivision ? (q & 1L) != 0L : mq.isOdd();
79.1284 - }
79.1285 - }
79.1286 - BigDecimal res;
79.1287 - if (isLongDivision)
79.1288 - res = new BigDecimal(null, (increment ? q + qsign : q), scale, 0);
79.1289 - else {
79.1290 - if (increment)
79.1291 - mq.add(MutableBigInteger.ONE);
79.1292 - res = mq.toBigDecimal(qsign, scale);
79.1293 - }
79.1294 - if (isRemainderZero && preferredScale != scale)
79.1295 - res.stripZerosToMatchScale(preferredScale);
79.1296 - return res;
79.1297 }
79.1298
79.1299 /**
79.1300 @@ -1541,7 +1628,7 @@
79.1301 * @see #ROUND_UNNECESSARY
79.1302 */
79.1303 public BigDecimal divide(BigDecimal divisor, int roundingMode) {
79.1304 - return this.divide(divisor, scale, roundingMode);
79.1305 + return this.divide(divisor, scale, roundingMode);
79.1306 }
79.1307
79.1308 /**
79.1309 @@ -1588,15 +1675,11 @@
79.1310 }
79.1311
79.1312 // Calculate preferred scale
79.1313 - int preferredScale = saturateLong((long)this.scale - divisor.scale);
79.1314 - if (this.signum() == 0) // 0/y
79.1315 - return (preferredScale >= 0 &&
79.1316 - preferredScale < ZERO_SCALED_BY.length) ?
79.1317 - ZERO_SCALED_BY[preferredScale] :
79.1318 - BigDecimal.valueOf(0, preferredScale);
79.1319 + int preferredScale = saturateLong((long) this.scale - divisor.scale);
79.1320 +
79.1321 + if (this.signum() == 0) // 0/y
79.1322 + return zeroValueOf(preferredScale);
79.1323 else {
79.1324 - this.inflate();
79.1325 - divisor.inflate();
79.1326 /*
79.1327 * If the quotient this/divisor has a terminating decimal
79.1328 * expansion, the expansion can have no more than
79.1329 @@ -1623,7 +1706,6 @@
79.1330 // the desired one by removing trailing zeros; since the
79.1331 // exact divide method does not have an explicit digit
79.1332 // limit, we can add zeros too.
79.1333 -
79.1334 if (preferredScale > quotientScale)
79.1335 return quotient.setScale(preferredScale, ROUND_UNNECESSARY);
79.1336
79.1337 @@ -1668,38 +1750,23 @@
79.1338 throw new ArithmeticException("Division undefined"); // NaN
79.1339 throw new ArithmeticException("Division by zero");
79.1340 }
79.1341 - if (dividend.signum() == 0) // 0/y
79.1342 - return new BigDecimal(BigInteger.ZERO, 0,
79.1343 - saturateLong(preferredScale), 1);
79.1344 -
79.1345 - // Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.1346 + if (dividend.signum() == 0) // 0/y
79.1347 + return zeroValueOf(saturateLong(preferredScale));
79.1348 int xscale = dividend.precision();
79.1349 int yscale = divisor.precision();
79.1350 - dividend = new BigDecimal(dividend.intVal, dividend.intCompact,
79.1351 - xscale, xscale);
79.1352 - divisor = new BigDecimal(divisor.intVal, divisor.intCompact,
79.1353 - yscale, yscale);
79.1354 - if (dividend.compareMagnitude(divisor) > 0) // satisfy constraint (b)
79.1355 - yscale = divisor.scale -= 1; // [that is, divisor *= 10]
79.1356 -
79.1357 - // In order to find out whether the divide generates the exact result,
79.1358 - // we avoid calling the above divide method. 'quotient' holds the
79.1359 - // return BigDecimal object whose scale will be set to 'scl'.
79.1360 - BigDecimal quotient;
79.1361 - int scl = checkScale(preferredScale + yscale - xscale + mcp);
79.1362 - if (checkScale((long)mcp + yscale) > xscale)
79.1363 - dividend = dividend.setScale(mcp + yscale, ROUND_UNNECESSARY);
79.1364 - else
79.1365 - divisor = divisor.setScale(checkScale((long)xscale - mcp),
79.1366 - ROUND_UNNECESSARY);
79.1367 - quotient = divideAndRound(dividend.intCompact, dividend.intVal,
79.1368 - divisor.intCompact, divisor.intVal,
79.1369 - scl, mc.roundingMode.oldMode,
79.1370 - checkScale(preferredScale));
79.1371 - // doRound, here, only affects 1000000000 case.
79.1372 - quotient = doRound(quotient, mc);
79.1373 -
79.1374 - return quotient;
79.1375 + if(dividend.intCompact!=INFLATED) {
79.1376 + if(divisor.intCompact!=INFLATED) {
79.1377 + return divide(dividend.intCompact, xscale, divisor.intCompact, yscale, preferredScale, mc);
79.1378 + } else {
79.1379 + return divide(dividend.intCompact, xscale, divisor.intVal, yscale, preferredScale, mc);
79.1380 + }
79.1381 + } else {
79.1382 + if(divisor.intCompact!=INFLATED) {
79.1383 + return divide(dividend.intVal, xscale, divisor.intCompact, yscale, preferredScale, mc);
79.1384 + } else {
79.1385 + return divide(dividend.intVal, xscale, divisor.intVal, yscale, preferredScale, mc);
79.1386 + }
79.1387 + }
79.1388 }
79.1389
79.1390 /**
79.1391 @@ -1715,13 +1782,13 @@
79.1392 */
79.1393 public BigDecimal divideToIntegralValue(BigDecimal divisor) {
79.1394 // Calculate preferred scale
79.1395 - int preferredScale = saturateLong((long)this.scale - divisor.scale);
79.1396 + int preferredScale = saturateLong((long) this.scale - divisor.scale);
79.1397 if (this.compareMagnitude(divisor) < 0) {
79.1398 // much faster when this << divisor
79.1399 - return BigDecimal.valueOf(0, preferredScale);
79.1400 + return zeroValueOf(preferredScale);
79.1401 }
79.1402
79.1403 - if(this.signum() == 0 && divisor.signum() != 0)
79.1404 + if (this.signum() == 0 && divisor.signum() != 0)
79.1405 return this.setScale(preferredScale, ROUND_UNNECESSARY);
79.1406
79.1407 // Perform a divide with enough digits to round to a correct
79.1408 @@ -1735,13 +1802,14 @@
79.1409 RoundingMode.DOWN));
79.1410 if (quotient.scale > 0) {
79.1411 quotient = quotient.setScale(0, RoundingMode.DOWN);
79.1412 - quotient.stripZerosToMatchScale(preferredScale);
79.1413 + quotient = stripZerosToMatchScale(quotient.intVal, quotient.intCompact, quotient.scale, preferredScale);
79.1414 }
79.1415
79.1416 if (quotient.scale < preferredScale) {
79.1417 // pad with zeros if necessary
79.1418 quotient = quotient.setScale(preferredScale, ROUND_UNNECESSARY);
79.1419 }
79.1420 +
79.1421 return quotient;
79.1422 }
79.1423
79.1424 @@ -1766,8 +1834,8 @@
79.1425 * @author Joseph D. Darcy
79.1426 */
79.1427 public BigDecimal divideToIntegralValue(BigDecimal divisor, MathContext mc) {
79.1428 - if (mc.precision == 0 || // exact result
79.1429 - (this.compareMagnitude(divisor) < 0) ) // zero result
79.1430 + if (mc.precision == 0 || // exact result
79.1431 + (this.compareMagnitude(divisor) < 0)) // zero result
79.1432 return divideToIntegralValue(divisor);
79.1433
79.1434 // Calculate preferred scale
79.1435 @@ -1780,8 +1848,7 @@
79.1436 * digits. Next, remove any fractional digits from the
79.1437 * quotient and adjust the scale to the preferred value.
79.1438 */
79.1439 - BigDecimal result = this.
79.1440 - divide(divisor, new MathContext(mc.precision, RoundingMode.DOWN));
79.1441 + BigDecimal result = this.divide(divisor, new MathContext(mc.precision, RoundingMode.DOWN));
79.1442
79.1443 if (result.scale() < 0) {
79.1444 /*
79.1445 @@ -1811,8 +1878,7 @@
79.1446 return result.setScale(result.scale() +
79.1447 Math.min(precisionDiff, preferredScale - result.scale) );
79.1448 } else {
79.1449 - result.stripZerosToMatchScale(preferredScale);
79.1450 - return result;
79.1451 + return stripZerosToMatchScale(result.intVal,result.intCompact,result.scale,preferredScale);
79.1452 }
79.1453 }
79.1454
79.1455 @@ -1954,8 +2020,7 @@
79.1456 // No need to calculate pow(n) if result will over/underflow.
79.1457 // Don't attempt to support "supernormal" numbers.
79.1458 int newScale = checkScale((long)scale * n);
79.1459 - this.inflate();
79.1460 - return new BigDecimal(intVal.pow(n), newScale);
79.1461 + return new BigDecimal(this.inflated().pow(n), newScale);
79.1462 }
79.1463
79.1464
79.1465 @@ -2016,12 +2081,10 @@
79.1466 throw new ArithmeticException("Invalid operation");
79.1467 if (n == 0)
79.1468 return ONE; // x**0 == 1 in X3.274
79.1469 - this.inflate();
79.1470 BigDecimal lhs = this;
79.1471 MathContext workmc = mc; // working settings
79.1472 int mag = Math.abs(n); // magnitude of n
79.1473 if (mc.precision > 0) {
79.1474 -
79.1475 int elength = longDigitLength(mag); // length of n in digits
79.1476 if (elength > mc.precision) // X3.274 rule
79.1477 throw new ArithmeticException("Invalid operation");
79.1478 @@ -2044,7 +2107,7 @@
79.1479 // else (!seenbit) no point in squaring ONE
79.1480 }
79.1481 // if negative n, calculate the reciprocal using working precision
79.1482 - if (n<0) // [hence mc.precision>0]
79.1483 + if (n < 0) // [hence mc.precision>0]
79.1484 acc=ONE.divide(acc, workmc);
79.1485 // round to final precision and strip zeros
79.1486 return doRound(acc, mc);
79.1487 @@ -2083,14 +2146,11 @@
79.1488 * @return {@code -this}.
79.1489 */
79.1490 public BigDecimal negate() {
79.1491 - BigDecimal result;
79.1492 - if (intCompact != INFLATED)
79.1493 - result = BigDecimal.valueOf(-intCompact, scale);
79.1494 - else {
79.1495 - result = new BigDecimal(intVal.negate(), scale);
79.1496 - result.precision = precision;
79.1497 + if (intCompact == INFLATED) {
79.1498 + return new BigDecimal(intVal.negate(), INFLATED, scale, precision);
79.1499 + } else {
79.1500 + return valueOf(-intCompact, scale, precision);
79.1501 }
79.1502 - return result;
79.1503 }
79.1504
79.1505 /**
79.1506 @@ -2186,7 +2246,7 @@
79.1507 if (s != INFLATED)
79.1508 result = longDigitLength(s);
79.1509 else
79.1510 - result = bigDigitLength(inflate());
79.1511 + result = bigDigitLength(intVal);
79.1512 precision = result;
79.1513 }
79.1514 return result;
79.1515 @@ -2202,7 +2262,7 @@
79.1516 * @since 1.2
79.1517 */
79.1518 public BigInteger unscaledValue() {
79.1519 - return this.inflate();
79.1520 + return this.inflated();
79.1521 }
79.1522
79.1523 // Rounding Modes
79.1524 @@ -2383,29 +2443,41 @@
79.1525 if (newScale == oldScale) // easy case
79.1526 return this;
79.1527 if (this.signum() == 0) // zero can have any scale
79.1528 - return BigDecimal.valueOf(0, newScale);
79.1529 -
79.1530 - long rs = this.intCompact;
79.1531 - if (newScale > oldScale) {
79.1532 - int raise = checkScale((long)newScale - oldScale);
79.1533 - BigInteger rb = null;
79.1534 - if (rs == INFLATED ||
79.1535 - (rs = longMultiplyPowerTen(rs, raise)) == INFLATED)
79.1536 - rb = bigMultiplyPowerTen(raise);
79.1537 - return new BigDecimal(rb, rs, newScale,
79.1538 - (precision > 0) ? precision + raise : 0);
79.1539 + return zeroValueOf(newScale);
79.1540 + if(this.intCompact!=INFLATED) {
79.1541 + long rs = this.intCompact;
79.1542 + if (newScale > oldScale) {
79.1543 + int raise = checkScale((long) newScale - oldScale);
79.1544 + if ((rs = longMultiplyPowerTen(rs, raise)) != INFLATED) {
79.1545 + return valueOf(rs,newScale);
79.1546 + }
79.1547 + BigInteger rb = bigMultiplyPowerTen(raise);
79.1548 + return new BigDecimal(rb, INFLATED, newScale, (precision > 0) ? precision + raise : 0);
79.1549 + } else {
79.1550 + // newScale < oldScale -- drop some digits
79.1551 + // Can't predict the precision due to the effect of rounding.
79.1552 + int drop = checkScale((long) oldScale - newScale);
79.1553 + if (drop < LONG_TEN_POWERS_TABLE.length) {
79.1554 + return divideAndRound(rs, LONG_TEN_POWERS_TABLE[drop], newScale, roundingMode, newScale);
79.1555 + } else {
79.1556 + return divideAndRound(this.inflated(), bigTenToThe(drop), newScale, roundingMode, newScale);
79.1557 + }
79.1558 + }
79.1559 } else {
79.1560 - // newScale < oldScale -- drop some digits
79.1561 - // Can't predict the precision due to the effect of rounding.
79.1562 - int drop = checkScale((long)oldScale - newScale);
79.1563 - if (drop < LONG_TEN_POWERS_TABLE.length)
79.1564 - return divideAndRound(rs, this.intVal,
79.1565 - LONG_TEN_POWERS_TABLE[drop], null,
79.1566 - newScale, roundingMode, newScale);
79.1567 - else
79.1568 - return divideAndRound(rs, this.intVal,
79.1569 - INFLATED, bigTenToThe(drop),
79.1570 - newScale, roundingMode, newScale);
79.1571 + if (newScale > oldScale) {
79.1572 + int raise = checkScale((long) newScale - oldScale);
79.1573 + BigInteger rb = bigMultiplyPowerTen(this.intVal,raise);
79.1574 + return new BigDecimal(rb, INFLATED, newScale, (precision > 0) ? precision + raise : 0);
79.1575 + } else {
79.1576 + // newScale < oldScale -- drop some digits
79.1577 + // Can't predict the precision due to the effect of rounding.
79.1578 + int drop = checkScale((long) oldScale - newScale);
79.1579 + if (drop < LONG_TEN_POWERS_TABLE.length)
79.1580 + return divideAndRound(this.intVal, LONG_TEN_POWERS_TABLE[drop], newScale, roundingMode,
79.1581 + newScale);
79.1582 + else
79.1583 + return divideAndRound(this.intVal, bigTenToThe(drop), newScale, roundingMode, newScale);
79.1584 + }
79.1585 }
79.1586 }
79.1587
79.1588 @@ -2524,10 +2596,11 @@
79.1589 * @since 1.5
79.1590 */
79.1591 public BigDecimal stripTrailingZeros() {
79.1592 - this.inflate();
79.1593 - BigDecimal result = new BigDecimal(intVal, scale);
79.1594 - result.stripZerosToMatchScale(Long.MIN_VALUE);
79.1595 - return result;
79.1596 + if(intCompact!=INFLATED) {
79.1597 + return createAndStripZerosToMatchScale(intCompact, scale, Long.MIN_VALUE);
79.1598 + } else {
79.1599 + return createAndStripZerosToMatchScale(intVal, scale, Long.MIN_VALUE);
79.1600 + }
79.1601 }
79.1602
79.1603 // Comparison Operations
79.1604 @@ -2647,7 +2720,7 @@
79.1605 } else if (xs != INFLATED)
79.1606 return xs == compactValFor(this.intVal);
79.1607
79.1608 - return this.inflate().equals(xDec.inflate());
79.1609 + return this.inflated().equals(xDec.inflated());
79.1610 }
79.1611
79.1612 /**
79.1613 @@ -2872,13 +2945,38 @@
79.1614 * @see #toEngineeringString()
79.1615 */
79.1616 public String toPlainString() {
79.1617 - BigDecimal bd = this;
79.1618 - if (bd.scale < 0)
79.1619 - bd = bd.setScale(0);
79.1620 - bd.inflate();
79.1621 - if (bd.scale == 0) // No decimal point
79.1622 - return bd.intVal.toString();
79.1623 - return bd.getValueString(bd.signum(), bd.intVal.abs().toString(), bd.scale);
79.1624 + if(scale==0) {
79.1625 + if(intCompact!=INFLATED) {
79.1626 + return Long.toString(intCompact);
79.1627 + } else {
79.1628 + return intVal.toString();
79.1629 + }
79.1630 + }
79.1631 + if(this.scale<0) { // No decimal point
79.1632 + if(signum()==0) {
79.1633 + return "0";
79.1634 + }
79.1635 + int tailingZeros = checkScaleNonZero((-(long)scale));
79.1636 + StringBuilder buf;
79.1637 + if(intCompact!=INFLATED) {
79.1638 + buf = new StringBuilder(20+tailingZeros);
79.1639 + buf.append(intCompact);
79.1640 + } else {
79.1641 + String str = intVal.toString();
79.1642 + buf = new StringBuilder(str.length()+tailingZeros);
79.1643 + buf.append(str);
79.1644 + }
79.1645 + for (int i = 0; i < tailingZeros; i++)
79.1646 + buf.append('0');
79.1647 + return buf.toString();
79.1648 + }
79.1649 + String str ;
79.1650 + if(intCompact!=INFLATED) {
79.1651 + str = Long.toString(Math.abs(intCompact));
79.1652 + } else {
79.1653 + str = intVal.abs().toString();
79.1654 + }
79.1655 + return getValueString(signum(), str, scale);
79.1656 }
79.1657
79.1658 /* Returns a digit.digit string */
79.1659 @@ -2922,7 +3020,7 @@
79.1660 */
79.1661 public BigInteger toBigInteger() {
79.1662 // force to an integer, quietly
79.1663 - return this.setScale(0, ROUND_DOWN).inflate();
79.1664 + return this.setScale(0, ROUND_DOWN).inflated();
79.1665 }
79.1666
79.1667 /**
79.1668 @@ -2937,7 +3035,7 @@
79.1669 */
79.1670 public BigInteger toBigIntegerExact() {
79.1671 // round to an integer, with Exception if decimal part non-0
79.1672 - return this.setScale(0, ROUND_UNNECESSARY).inflate();
79.1673 + return this.setScale(0, ROUND_UNNECESSARY).inflated();
79.1674 }
79.1675
79.1676 /**
79.1677 @@ -2990,7 +3088,7 @@
79.1678 BigDecimal num = this.setScale(0, ROUND_UNNECESSARY);
79.1679 if (num.precision() >= 19) // need to check carefully
79.1680 LongOverflow.check(num);
79.1681 - return num.inflate().longValue();
79.1682 + return num.inflated().longValue();
79.1683 }
79.1684
79.1685 private static class LongOverflow {
79.1686 @@ -3001,9 +3099,9 @@
79.1687 private static final BigInteger LONGMAX = BigInteger.valueOf(Long.MAX_VALUE);
79.1688
79.1689 public static void check(BigDecimal num) {
79.1690 - num.inflate();
79.1691 - if ((num.intVal.compareTo(LONGMIN) < 0) ||
79.1692 - (num.intVal.compareTo(LONGMAX) > 0))
79.1693 + BigInteger intVal = num.inflated();
79.1694 + if (intVal.compareTo(LONGMIN) < 0 ||
79.1695 + intVal.compareTo(LONGMAX) > 0)
79.1696 throw new java.lang.ArithmeticException("Overflow");
79.1697 }
79.1698 }
79.1699 @@ -3107,8 +3205,28 @@
79.1700 * @return this {@code BigDecimal} converted to a {@code float}.
79.1701 */
79.1702 public float floatValue(){
79.1703 - if (scale == 0 && intCompact != INFLATED)
79.1704 + if(intCompact != INFLATED) {
79.1705 + if (scale == 0) {
79.1706 return (float)intCompact;
79.1707 + } else {
79.1708 + /*
79.1709 + * If both intCompact and the scale can be exactly
79.1710 + * represented as float values, perform a single float
79.1711 + * multiply or divide to compute the (properly
79.1712 + * rounded) result.
79.1713 + */
79.1714 + if (Math.abs(intCompact) < 1L<<22 ) {
79.1715 + // Don't have too guard against
79.1716 + // Math.abs(MIN_VALUE) because of outer check
79.1717 + // against INFLATED.
79.1718 + if (scale > 0 && scale < float10pow.length) {
79.1719 + return (float)intCompact / float10pow[scale];
79.1720 + } else if (scale < 0 && scale > -float10pow.length) {
79.1721 + return (float)intCompact * float10pow[-scale];
79.1722 + }
79.1723 + }
79.1724 + }
79.1725 + }
79.1726 // Somewhat inefficient, but guaranteed to work.
79.1727 return Float.parseFloat(this.toString());
79.1728 }
79.1729 @@ -3130,13 +3248,53 @@
79.1730 * @return this {@code BigDecimal} converted to a {@code double}.
79.1731 */
79.1732 public double doubleValue(){
79.1733 - if (scale == 0 && intCompact != INFLATED)
79.1734 - return (double)intCompact;
79.1735 + if(intCompact != INFLATED) {
79.1736 + if (scale == 0) {
79.1737 + return (double)intCompact;
79.1738 + } else {
79.1739 + /*
79.1740 + * If both intCompact and the scale can be exactly
79.1741 + * represented as double values, perform a single
79.1742 + * double multiply or divide to compute the (properly
79.1743 + * rounded) result.
79.1744 + */
79.1745 + if (Math.abs(intCompact) < 1L<<52 ) {
79.1746 + // Don't have too guard against
79.1747 + // Math.abs(MIN_VALUE) because of outer check
79.1748 + // against INFLATED.
79.1749 + if (scale > 0 && scale < double10pow.length) {
79.1750 + return (double)intCompact / double10pow[scale];
79.1751 + } else if (scale < 0 && scale > -double10pow.length) {
79.1752 + return (double)intCompact * double10pow[-scale];
79.1753 + }
79.1754 + }
79.1755 + }
79.1756 + }
79.1757 // Somewhat inefficient, but guaranteed to work.
79.1758 return Double.parseDouble(this.toString());
79.1759 }
79.1760
79.1761 /**
79.1762 + * Powers of 10 which can be represented exactly in {@code
79.1763 + * double}.
79.1764 + */
79.1765 + private static final double double10pow[] = {
79.1766 + 1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5,
79.1767 + 1.0e6, 1.0e7, 1.0e8, 1.0e9, 1.0e10, 1.0e11,
79.1768 + 1.0e12, 1.0e13, 1.0e14, 1.0e15, 1.0e16, 1.0e17,
79.1769 + 1.0e18, 1.0e19, 1.0e20, 1.0e21, 1.0e22
79.1770 + };
79.1771 +
79.1772 + /**
79.1773 + * Powers of 10 which can be represented exactly in {@code
79.1774 + * float}.
79.1775 + */
79.1776 + private static final float float10pow[] = {
79.1777 + 1.0e0f, 1.0e1f, 1.0e2f, 1.0e3f, 1.0e4f, 1.0e5f,
79.1778 + 1.0e6f, 1.0e7f, 1.0e8f, 1.0e9f, 1.0e10f
79.1779 + };
79.1780 +
79.1781 + /**
79.1782 * Returns the size of an ulp, a unit in the last place, of this
79.1783 * {@code BigDecimal}. An ulp of a nonzero {@code BigDecimal}
79.1784 * value is the positive distance between this value and the
79.1785 @@ -3151,10 +3309,9 @@
79.1786 * @since 1.5
79.1787 */
79.1788 public BigDecimal ulp() {
79.1789 - return BigDecimal.valueOf(1, this.scale());
79.1790 + return BigDecimal.valueOf(1, this.scale(), 1);
79.1791 }
79.1792
79.1793 -
79.1794 // Private class to build a string representation for BigDecimal object.
79.1795 // "StringBuilderHelper" is constructed as a thread local variable so it is
79.1796 // thread safe. The StringBuilder field acts as a buffer to hold the temporary
79.1797 @@ -3268,6 +3425,15 @@
79.1798 return (intCompact != INFLATED) ?
79.1799 Long.toString(intCompact):
79.1800 intVal.toString();
79.1801 + if (scale == 2 &&
79.1802 + intCompact >= 0 && intCompact < Integer.MAX_VALUE) {
79.1803 + // currency fast path
79.1804 + int lowInt = (int)intCompact % 100;
79.1805 + int highInt = (int)intCompact / 100;
79.1806 + return (Integer.toString(highInt) + '.' +
79.1807 + StringBuilderHelper.DIGIT_TENS[lowInt] +
79.1808 + StringBuilderHelper.DIGIT_ONES[lowInt]) ;
79.1809 + }
79.1810
79.1811 StringBuilderHelper sbHelper = threadLocalStringBuilderHelper.get();
79.1812 char[] coeff;
79.1813 @@ -3377,7 +3543,7 @@
79.1814 tenpow[0] = '1';
79.1815 for (int i = 1; i <= n; i++)
79.1816 tenpow[i] = '0';
79.1817 - return new BigInteger(tenpow);
79.1818 + return new BigInteger(tenpow,1, tenpow.length);
79.1819 }
79.1820
79.1821 /**
79.1822 @@ -3433,11 +3599,16 @@
79.1823 1000000000000000000L // 18 / 10^18
79.1824 };
79.1825
79.1826 - private static volatile BigInteger BIG_TEN_POWERS_TABLE[] = {BigInteger.ONE,
79.1827 - BigInteger.valueOf(10), BigInteger.valueOf(100),
79.1828 - BigInteger.valueOf(1000), BigInteger.valueOf(10000),
79.1829 - BigInteger.valueOf(100000), BigInteger.valueOf(1000000),
79.1830 - BigInteger.valueOf(10000000), BigInteger.valueOf(100000000),
79.1831 + private static volatile BigInteger BIG_TEN_POWERS_TABLE[] = {
79.1832 + BigInteger.ONE,
79.1833 + BigInteger.valueOf(10),
79.1834 + BigInteger.valueOf(100),
79.1835 + BigInteger.valueOf(1000),
79.1836 + BigInteger.valueOf(10000),
79.1837 + BigInteger.valueOf(100000),
79.1838 + BigInteger.valueOf(1000000),
79.1839 + BigInteger.valueOf(10000000),
79.1840 + BigInteger.valueOf(100000000),
79.1841 BigInteger.valueOf(1000000000),
79.1842 BigInteger.valueOf(10000000000L),
79.1843 BigInteger.valueOf(100000000000L),
79.1844 @@ -3502,7 +3673,7 @@
79.1845 */
79.1846 private BigInteger bigMultiplyPowerTen(int n) {
79.1847 if (n <= 0)
79.1848 - return this.inflate();
79.1849 + return this.inflated();
79.1850
79.1851 if (intCompact != INFLATED)
79.1852 return bigTenToThe(n).multiply(intCompact);
79.1853 @@ -3511,12 +3682,13 @@
79.1854 }
79.1855
79.1856 /**
79.1857 - * Assign appropriate BigInteger to intVal field if intVal is
79.1858 + * Returns appropriate BigInteger from intVal field if intVal is
79.1859 * null, i.e. the compact representation is in use.
79.1860 */
79.1861 - private BigInteger inflate() {
79.1862 - if (intVal == null)
79.1863 - intVal = BigInteger.valueOf(intCompact);
79.1864 + private BigInteger inflated() {
79.1865 + if (intVal == null) {
79.1866 + return BigInteger.valueOf(intCompact);
79.1867 + }
79.1868 return intVal;
79.1869 }
79.1870
79.1871 @@ -3543,6 +3715,30 @@
79.1872 }
79.1873 }
79.1874
79.1875 + private static class UnsafeHolder {
79.1876 + private static final sun.misc.Unsafe unsafe;
79.1877 + private static final long intCompactOffset;
79.1878 + private static final long intValOffset;
79.1879 + static {
79.1880 + try {
79.1881 + unsafe = sun.misc.Unsafe.getUnsafe();
79.1882 + intCompactOffset = unsafe.objectFieldOffset
79.1883 + (BigDecimal.class.getDeclaredField("intCompact"));
79.1884 + intValOffset = unsafe.objectFieldOffset
79.1885 + (BigDecimal.class.getDeclaredField("intVal"));
79.1886 + } catch (Exception ex) {
79.1887 + throw new ExceptionInInitializerError(ex);
79.1888 + }
79.1889 + }
79.1890 + static void setIntCompactVolatile(BigDecimal bd, long val) {
79.1891 + unsafe.putLongVolatile(bd, intCompactOffset, val);
79.1892 + }
79.1893 +
79.1894 + static void setIntValVolatile(BigDecimal bd, BigInteger val) {
79.1895 + unsafe.putObjectVolatile(bd, intValOffset, val);
79.1896 + }
79.1897 + }
79.1898 +
79.1899 /**
79.1900 * Reconstitute the {@code BigDecimal} instance from a stream (that is,
79.1901 * deserialize it).
79.1902 @@ -3559,7 +3755,7 @@
79.1903 throw new java.io.StreamCorruptedException(message);
79.1904 // [all values of scale are now allowed]
79.1905 }
79.1906 - intCompact = compactValFor(intVal);
79.1907 + UnsafeHolder.setIntCompactVolatile(this, compactValFor(intVal));
79.1908 }
79.1909
79.1910 /**
79.1911 @@ -3570,13 +3766,12 @@
79.1912 private void writeObject(java.io.ObjectOutputStream s)
79.1913 throws java.io.IOException {
79.1914 // Must inflate to maintain compatible serial form.
79.1915 - this.inflate();
79.1916 -
79.1917 - // Write proper fields
79.1918 + if (this.intVal == null)
79.1919 + UnsafeHolder.setIntValVolatile(this, BigInteger.valueOf(this.intCompact));
79.1920 + // Could reset intVal back to null if it has to be set.
79.1921 s.defaultWriteObject();
79.1922 }
79.1923
79.1924 -
79.1925 /**
79.1926 * Returns the length of the absolute value of a {@code long}, in decimal
79.1927 * digits.
79.1928 @@ -3584,36 +3779,29 @@
79.1929 * @param x the {@code long}
79.1930 * @return the length of the unscaled value, in deciaml digits.
79.1931 */
79.1932 - private static int longDigitLength(long x) {
79.1933 + static int longDigitLength(long x) {
79.1934 /*
79.1935 * As described in "Bit Twiddling Hacks" by Sean Anderson,
79.1936 * (http://graphics.stanford.edu/~seander/bithacks.html)
79.1937 - * integer log 10 of x is within 1 of
79.1938 - * (1233/4096)* (1 + integer log 2 of x).
79.1939 - * The fraction 1233/4096 approximates log10(2). So we first
79.1940 - * do a version of log2 (a variant of Long class with
79.1941 - * pre-checks and opposite directionality) and then scale and
79.1942 - * check against powers table. This is a little simpler in
79.1943 - * present context than the version in Hacker's Delight sec
79.1944 - * 11-4. Adding one to bit length allows comparing downward
79.1945 - * from the LONG_TEN_POWERS_TABLE that we need anyway.
79.1946 + * integer log 10 of x is within 1 of (1233/4096)* (1 +
79.1947 + * integer log 2 of x). The fraction 1233/4096 approximates
79.1948 + * log10(2). So we first do a version of log2 (a variant of
79.1949 + * Long class with pre-checks and opposite directionality) and
79.1950 + * then scale and check against powers table. This is a little
79.1951 + * simpler in present context than the version in Hacker's
79.1952 + * Delight sec 11-4. Adding one to bit length allows comparing
79.1953 + * downward from the LONG_TEN_POWERS_TABLE that we need
79.1954 + * anyway.
79.1955 */
79.1956 - assert x != INFLATED;
79.1957 + assert x != BigDecimal.INFLATED;
79.1958 if (x < 0)
79.1959 x = -x;
79.1960 if (x < 10) // must screen for 0, might as well 10
79.1961 return 1;
79.1962 - int n = 64; // not 63, to avoid needing to add 1 later
79.1963 - int y = (int)(x >>> 32);
79.1964 - if (y == 0) { n -= 32; y = (int)x; }
79.1965 - if (y >>> 16 == 0) { n -= 16; y <<= 16; }
79.1966 - if (y >>> 24 == 0) { n -= 8; y <<= 8; }
79.1967 - if (y >>> 28 == 0) { n -= 4; y <<= 4; }
79.1968 - if (y >>> 30 == 0) { n -= 2; y <<= 2; }
79.1969 - int r = (((y >>> 31) + n) * 1233) >>> 12;
79.1970 + int r = ((64 - Long.numberOfLeadingZeros(x) + 1) * 1233) >>> 12;
79.1971 long[] tab = LONG_TEN_POWERS_TABLE;
79.1972 // if r >= length, must have max possible digits for long
79.1973 - return (r >= tab.length || x < tab[r])? r : r+1;
79.1974 + return (r >= tab.length || x < tab[r]) ? r : r + 1;
79.1975 }
79.1976
79.1977 /**
79.1978 @@ -3635,41 +3823,6 @@
79.1979 return b.compareMagnitude(bigTenToThe(r)) < 0? r : r+1;
79.1980 }
79.1981
79.1982 -
79.1983 - /**
79.1984 - * Remove insignificant trailing zeros from this
79.1985 - * {@code BigDecimal} until the preferred scale is reached or no
79.1986 - * more zeros can be removed. If the preferred scale is less than
79.1987 - * Integer.MIN_VALUE, all the trailing zeros will be removed.
79.1988 - *
79.1989 - * {@code BigInteger} assistance could help, here?
79.1990 - *
79.1991 - * <p>WARNING: This method should only be called on new objects as
79.1992 - * it mutates the value fields.
79.1993 - *
79.1994 - * @return this {@code BigDecimal} with a scale possibly reduced
79.1995 - * to be closed to the preferred scale.
79.1996 - */
79.1997 - private BigDecimal stripZerosToMatchScale(long preferredScale) {
79.1998 - this.inflate();
79.1999 - BigInteger qr[]; // quotient-remainder pair
79.2000 - while ( intVal.compareMagnitude(BigInteger.TEN) >= 0 &&
79.2001 - scale > preferredScale) {
79.2002 - if (intVal.testBit(0))
79.2003 - break; // odd number cannot end in 0
79.2004 - qr = intVal.divideAndRemainder(BigInteger.TEN);
79.2005 - if (qr[1].signum() != 0)
79.2006 - break; // non-0 remainder
79.2007 - intVal=qr[0];
79.2008 - scale = checkScale((long)scale-1); // could Overflow
79.2009 - if (precision > 0) // adjust precision if known
79.2010 - precision--;
79.2011 - }
79.2012 - if (intVal != null)
79.2013 - intCompact = compactValFor(intVal);
79.2014 - return this;
79.2015 - }
79.2016 -
79.2017 /**
79.2018 * Check a scale for Underflow or Overflow. If this BigDecimal is
79.2019 * nonzero, throw an exception if the scale is outof range. If this
79.2020 @@ -3693,74 +3846,7 @@
79.2021 return asInt;
79.2022 }
79.2023
79.2024 - /**
79.2025 - * Round an operand; used only if digits > 0. Does not change
79.2026 - * {@code this}; if rounding is needed a new {@code BigDecimal}
79.2027 - * is created and returned.
79.2028 - *
79.2029 - * @param mc the context to use.
79.2030 - * @throws ArithmeticException if the result is inexact but the
79.2031 - * rounding mode is {@code UNNECESSARY}.
79.2032 - */
79.2033 - private BigDecimal roundOp(MathContext mc) {
79.2034 - BigDecimal rounded = doRound(this, mc);
79.2035 - return rounded;
79.2036 - }
79.2037 -
79.2038 - /** Round this BigDecimal according to the MathContext settings;
79.2039 - * used only if precision {@literal >} 0.
79.2040 - *
79.2041 - * <p>WARNING: This method should only be called on new objects as
79.2042 - * it mutates the value fields.
79.2043 - *
79.2044 - * @param mc the context to use.
79.2045 - * @throws ArithmeticException if the rounding mode is
79.2046 - * {@code RoundingMode.UNNECESSARY} and the
79.2047 - * {@code BigDecimal} operation would require rounding.
79.2048 - */
79.2049 - private void roundThis(MathContext mc) {
79.2050 - BigDecimal rounded = doRound(this, mc);
79.2051 - if (rounded == this) // wasn't rounded
79.2052 - return;
79.2053 - this.intVal = rounded.intVal;
79.2054 - this.intCompact = rounded.intCompact;
79.2055 - this.scale = rounded.scale;
79.2056 - this.precision = rounded.precision;
79.2057 - }
79.2058 -
79.2059 - /**
79.2060 - * Returns a {@code BigDecimal} rounded according to the
79.2061 - * MathContext settings; used only if {@code mc.precision > 0}.
79.2062 - * Does not change {@code this}; if rounding is needed a new
79.2063 - * {@code BigDecimal} is created and returned.
79.2064 - *
79.2065 - * @param mc the context to use.
79.2066 - * @return a {@code BigDecimal} rounded according to the MathContext
79.2067 - * settings. May return this, if no rounding needed.
79.2068 - * @throws ArithmeticException if the rounding mode is
79.2069 - * {@code RoundingMode.UNNECESSARY} and the
79.2070 - * result is inexact.
79.2071 - */
79.2072 - private static BigDecimal doRound(BigDecimal d, MathContext mc) {
79.2073 - int mcp = mc.precision;
79.2074 - int drop;
79.2075 - // This might (rarely) iterate to cover the 999=>1000 case
79.2076 - while ((drop = d.precision() - mcp) > 0) {
79.2077 - int newScale = d.checkScale((long)d.scale - drop);
79.2078 - int mode = mc.roundingMode.oldMode;
79.2079 - if (drop < LONG_TEN_POWERS_TABLE.length)
79.2080 - d = divideAndRound(d.intCompact, d.intVal,
79.2081 - LONG_TEN_POWERS_TABLE[drop], null,
79.2082 - newScale, mode, newScale);
79.2083 - else
79.2084 - d = divideAndRound(d.intCompact, d.intVal,
79.2085 - INFLATED, bigTenToThe(drop),
79.2086 - newScale, mode, newScale);
79.2087 - }
79.2088 - return d;
79.2089 - }
79.2090 -
79.2091 - /**
79.2092 + /**
79.2093 * Returns the compact value for given {@code BigInteger}, or
79.2094 * INFLATED if too big. Relies on internal representation of
79.2095 * {@code BigInteger}.
79.2096 @@ -3852,4 +3938,1290 @@
79.2097 }
79.2098 return this;
79.2099 }
79.2100 +
79.2101 + /* the same as checkScale where value!=0 */
79.2102 + private static int checkScaleNonZero(long val) {
79.2103 + int asInt = (int)val;
79.2104 + if (asInt != val) {
79.2105 + throw new ArithmeticException(asInt>0 ? "Underflow":"Overflow");
79.2106 + }
79.2107 + return asInt;
79.2108 + }
79.2109 +
79.2110 + private static int checkScale(long intCompact, long val) {
79.2111 + int asInt = (int)val;
79.2112 + if (asInt != val) {
79.2113 + asInt = val>Integer.MAX_VALUE ? Integer.MAX_VALUE : Integer.MIN_VALUE;
79.2114 + if (intCompact != 0)
79.2115 + throw new ArithmeticException(asInt>0 ? "Underflow":"Overflow");
79.2116 + }
79.2117 + return asInt;
79.2118 + }
79.2119 +
79.2120 + private static int checkScale(BigInteger intVal, long val) {
79.2121 + int asInt = (int)val;
79.2122 + if (asInt != val) {
79.2123 + asInt = val>Integer.MAX_VALUE ? Integer.MAX_VALUE : Integer.MIN_VALUE;
79.2124 + if (intVal.signum() != 0)
79.2125 + throw new ArithmeticException(asInt>0 ? "Underflow":"Overflow");
79.2126 + }
79.2127 + return asInt;
79.2128 + }
79.2129 +
79.2130 + /**
79.2131 + * Returns a {@code BigDecimal} rounded according to the MathContext
79.2132 + * settings;
79.2133 + * If rounding is needed a new {@code BigDecimal} is created and returned.
79.2134 + *
79.2135 + * @param val the value to be rounded
79.2136 + * @param mc the context to use.
79.2137 + * @return a {@code BigDecimal} rounded according to the MathContext
79.2138 + * settings. May return {@code value}, if no rounding needed.
79.2139 + * @throws ArithmeticException if the rounding mode is
79.2140 + * {@code RoundingMode.UNNECESSARY} and the
79.2141 + * result is inexact.
79.2142 + */
79.2143 + private static BigDecimal doRound(BigDecimal val, MathContext mc) {
79.2144 + int mcp = mc.precision;
79.2145 + boolean wasDivided = false;
79.2146 + if (mcp > 0) {
79.2147 + BigInteger intVal = val.intVal;
79.2148 + long compactVal = val.intCompact;
79.2149 + int scale = val.scale;
79.2150 + int prec = val.precision();
79.2151 + int mode = mc.roundingMode.oldMode;
79.2152 + int drop;
79.2153 + if (compactVal == INFLATED) {
79.2154 + drop = prec - mcp;
79.2155 + while (drop > 0) {
79.2156 + scale = checkScaleNonZero((long) scale - drop);
79.2157 + intVal = divideAndRoundByTenPow(intVal, drop, mode);
79.2158 + wasDivided = true;
79.2159 + compactVal = compactValFor(intVal);
79.2160 + if (compactVal != INFLATED) {
79.2161 + prec = longDigitLength(compactVal);
79.2162 + break;
79.2163 + }
79.2164 + prec = bigDigitLength(intVal);
79.2165 + drop = prec - mcp;
79.2166 + }
79.2167 + }
79.2168 + if (compactVal != INFLATED) {
79.2169 + drop = prec - mcp; // drop can't be more than 18
79.2170 + while (drop > 0) {
79.2171 + scale = checkScaleNonZero((long) scale - drop);
79.2172 + compactVal = divideAndRound(compactVal, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.2173 + wasDivided = true;
79.2174 + prec = longDigitLength(compactVal);
79.2175 + drop = prec - mcp;
79.2176 + intVal = null;
79.2177 + }
79.2178 + }
79.2179 + return wasDivided ? new BigDecimal(intVal,compactVal,scale,prec) : val;
79.2180 + }
79.2181 + return val;
79.2182 + }
79.2183 +
79.2184 + /*
79.2185 + * Returns a {@code BigDecimal} created from {@code long} value with
79.2186 + * given scale rounded according to the MathContext settings
79.2187 + */
79.2188 + private static BigDecimal doRound(long compactVal, int scale, MathContext mc) {
79.2189 + int mcp = mc.precision;
79.2190 + if (mcp > 0 && mcp < 19) {
79.2191 + int prec = longDigitLength(compactVal);
79.2192 + int drop = prec - mcp; // drop can't be more than 18
79.2193 + while (drop > 0) {
79.2194 + scale = checkScaleNonZero((long) scale - drop);
79.2195 + compactVal = divideAndRound(compactVal, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.2196 + prec = longDigitLength(compactVal);
79.2197 + drop = prec - mcp;
79.2198 + }
79.2199 + return valueOf(compactVal, scale, prec);
79.2200 + }
79.2201 + return valueOf(compactVal, scale);
79.2202 + }
79.2203 +
79.2204 + /*
79.2205 + * Returns a {@code BigDecimal} created from {@code BigInteger} value with
79.2206 + * given scale rounded according to the MathContext settings
79.2207 + */
79.2208 + private static BigDecimal doRound(BigInteger intVal, int scale, MathContext mc) {
79.2209 + int mcp = mc.precision;
79.2210 + int prec = 0;
79.2211 + if (mcp > 0) {
79.2212 + long compactVal = compactValFor(intVal);
79.2213 + int mode = mc.roundingMode.oldMode;
79.2214 + int drop;
79.2215 + if (compactVal == INFLATED) {
79.2216 + prec = bigDigitLength(intVal);
79.2217 + drop = prec - mcp;
79.2218 + while (drop > 0) {
79.2219 + scale = checkScaleNonZero((long) scale - drop);
79.2220 + intVal = divideAndRoundByTenPow(intVal, drop, mode);
79.2221 + compactVal = compactValFor(intVal);
79.2222 + if (compactVal != INFLATED) {
79.2223 + break;
79.2224 + }
79.2225 + prec = bigDigitLength(intVal);
79.2226 + drop = prec - mcp;
79.2227 + }
79.2228 + }
79.2229 + if (compactVal != INFLATED) {
79.2230 + prec = longDigitLength(compactVal);
79.2231 + drop = prec - mcp; // drop can't be more than 18
79.2232 + while (drop > 0) {
79.2233 + scale = checkScaleNonZero((long) scale - drop);
79.2234 + compactVal = divideAndRound(compactVal, LONG_TEN_POWERS_TABLE[drop], mc.roundingMode.oldMode);
79.2235 + prec = longDigitLength(compactVal);
79.2236 + drop = prec - mcp;
79.2237 + }
79.2238 + return valueOf(compactVal,scale,prec);
79.2239 + }
79.2240 + }
79.2241 + return new BigDecimal(intVal,INFLATED,scale,prec);
79.2242 + }
79.2243 +
79.2244 + /*
79.2245 + * Divides {@code BigInteger} value by ten power.
79.2246 + */
79.2247 + private static BigInteger divideAndRoundByTenPow(BigInteger intVal, int tenPow, int roundingMode) {
79.2248 + if (tenPow < LONG_TEN_POWERS_TABLE.length)
79.2249 + intVal = divideAndRound(intVal, LONG_TEN_POWERS_TABLE[tenPow], roundingMode);
79.2250 + else
79.2251 + intVal = divideAndRound(intVal, bigTenToThe(tenPow), roundingMode);
79.2252 + return intVal;
79.2253 + }
79.2254 +
79.2255 + /**
79.2256 + * Internally used for division operation for division {@code long} by
79.2257 + * {@code long}.
79.2258 + * The returned {@code BigDecimal} object is the quotient whose scale is set
79.2259 + * to the passed in scale. If the remainder is not zero, it will be rounded
79.2260 + * based on the passed in roundingMode. Also, if the remainder is zero and
79.2261 + * the last parameter, i.e. preferredScale is NOT equal to scale, the
79.2262 + * trailing zeros of the result is stripped to match the preferredScale.
79.2263 + */
79.2264 + private static BigDecimal divideAndRound(long ldividend, long ldivisor, int scale, int roundingMode,
79.2265 + int preferredScale) {
79.2266 +
79.2267 + int qsign; // quotient sign
79.2268 + long q = ldividend / ldivisor; // store quotient in long
79.2269 + if (roundingMode == ROUND_DOWN && scale == preferredScale)
79.2270 + return valueOf(q, scale);
79.2271 + long r = ldividend % ldivisor; // store remainder in long
79.2272 + qsign = ((ldividend < 0) == (ldivisor < 0)) ? 1 : -1;
79.2273 + if (r != 0) {
79.2274 + boolean increment = needIncrement(ldivisor, roundingMode, qsign, q, r);
79.2275 + return valueOf((increment ? q + qsign : q), scale);
79.2276 + } else {
79.2277 + if (preferredScale != scale)
79.2278 + return createAndStripZerosToMatchScale(q, scale, preferredScale);
79.2279 + else
79.2280 + return valueOf(q, scale);
79.2281 + }
79.2282 + }
79.2283 +
79.2284 + /**
79.2285 + * Divides {@code long} by {@code long} and do rounding based on the
79.2286 + * passed in roundingMode.
79.2287 + */
79.2288 + private static long divideAndRound(long ldividend, long ldivisor, int roundingMode) {
79.2289 + int qsign; // quotient sign
79.2290 + long q = ldividend / ldivisor; // store quotient in long
79.2291 + if (roundingMode == ROUND_DOWN)
79.2292 + return q;
79.2293 + long r = ldividend % ldivisor; // store remainder in long
79.2294 + qsign = ((ldividend < 0) == (ldivisor < 0)) ? 1 : -1;
79.2295 + if (r != 0) {
79.2296 + boolean increment = needIncrement(ldivisor, roundingMode, qsign, q, r);
79.2297 + return increment ? q + qsign : q;
79.2298 + } else {
79.2299 + return q;
79.2300 + }
79.2301 + }
79.2302 +
79.2303 + /**
79.2304 + * Shared logic of need increment computation.
79.2305 + */
79.2306 + private static boolean commonNeedIncrement(int roundingMode, int qsign,
79.2307 + int cmpFracHalf, boolean oddQuot) {
79.2308 + switch(roundingMode) {
79.2309 + case ROUND_UNNECESSARY:
79.2310 + throw new ArithmeticException("Rounding necessary");
79.2311 +
79.2312 + case ROUND_UP: // Away from zero
79.2313 + return true;
79.2314 +
79.2315 + case ROUND_DOWN: // Towards zero
79.2316 + return false;
79.2317 +
79.2318 + case ROUND_CEILING: // Towards +infinity
79.2319 + return qsign > 0;
79.2320 +
79.2321 + case ROUND_FLOOR: // Towards -infinity
79.2322 + return qsign < 0;
79.2323 +
79.2324 + default: // Some kind of half-way rounding
79.2325 + assert roundingMode >= ROUND_HALF_UP &&
79.2326 + roundingMode <= ROUND_HALF_EVEN: "Unexpected rounding mode" + RoundingMode.valueOf(roundingMode);
79.2327 +
79.2328 + if (cmpFracHalf < 0 ) // We're closer to higher digit
79.2329 + return false;
79.2330 + else if (cmpFracHalf > 0 ) // We're closer to lower digit
79.2331 + return true;
79.2332 + else { // half-way
79.2333 + assert cmpFracHalf == 0;
79.2334 +
79.2335 + switch(roundingMode) {
79.2336 + case ROUND_HALF_DOWN:
79.2337 + return false;
79.2338 +
79.2339 + case ROUND_HALF_UP:
79.2340 + return true;
79.2341 +
79.2342 + case ROUND_HALF_EVEN:
79.2343 + return oddQuot;
79.2344 +
79.2345 + default:
79.2346 + throw new AssertionError("Unexpected rounding mode" + roundingMode);
79.2347 + }
79.2348 + }
79.2349 + }
79.2350 + }
79.2351 +
79.2352 + /**
79.2353 + * Tests if quotient has to be incremented according the roundingMode
79.2354 + */
79.2355 + private static boolean needIncrement(long ldivisor, int roundingMode,
79.2356 + int qsign, long q, long r) {
79.2357 + assert r != 0L;
79.2358 +
79.2359 + int cmpFracHalf;
79.2360 + if (r <= HALF_LONG_MIN_VALUE || r > HALF_LONG_MAX_VALUE) {
79.2361 + cmpFracHalf = 1; // 2 * r can't fit into long
79.2362 + } else {
79.2363 + cmpFracHalf = longCompareMagnitude(2 * r, ldivisor);
79.2364 + }
79.2365 +
79.2366 + return commonNeedIncrement(roundingMode, qsign, cmpFracHalf, (q & 1L) != 0L);
79.2367 + }
79.2368 +
79.2369 + /**
79.2370 + * Divides {@code BigInteger} value by {@code long} value and
79.2371 + * do rounding based on the passed in roundingMode.
79.2372 + */
79.2373 + private static BigInteger divideAndRound(BigInteger bdividend, long ldivisor, int roundingMode) {
79.2374 + boolean isRemainderZero; // record remainder is zero or not
79.2375 + int qsign; // quotient sign
79.2376 + long r = 0; // store quotient & remainder in long
79.2377 + MutableBigInteger mq = null; // store quotient
79.2378 + // Descend into mutables for faster remainder checks
79.2379 + MutableBigInteger mdividend = new MutableBigInteger(bdividend.mag);
79.2380 + mq = new MutableBigInteger();
79.2381 + r = mdividend.divide(ldivisor, mq);
79.2382 + isRemainderZero = (r == 0);
79.2383 + qsign = (ldivisor < 0) ? -bdividend.signum : bdividend.signum;
79.2384 + if (!isRemainderZero) {
79.2385 + if(needIncrement(ldivisor, roundingMode, qsign, mq, r)) {
79.2386 + mq.add(MutableBigInteger.ONE);
79.2387 + }
79.2388 + }
79.2389 + return mq.toBigInteger(qsign);
79.2390 + }
79.2391 +
79.2392 + /**
79.2393 + * Internally used for division operation for division {@code BigInteger}
79.2394 + * by {@code long}.
79.2395 + * The returned {@code BigDecimal} object is the quotient whose scale is set
79.2396 + * to the passed in scale. If the remainder is not zero, it will be rounded
79.2397 + * based on the passed in roundingMode. Also, if the remainder is zero and
79.2398 + * the last parameter, i.e. preferredScale is NOT equal to scale, the
79.2399 + * trailing zeros of the result is stripped to match the preferredScale.
79.2400 + */
79.2401 + private static BigDecimal divideAndRound(BigInteger bdividend,
79.2402 + long ldivisor, int scale, int roundingMode, int preferredScale) {
79.2403 + boolean isRemainderZero; // record remainder is zero or not
79.2404 + int qsign; // quotient sign
79.2405 + long r = 0; // store quotient & remainder in long
79.2406 + MutableBigInteger mq = null; // store quotient
79.2407 + // Descend into mutables for faster remainder checks
79.2408 + MutableBigInteger mdividend = new MutableBigInteger(bdividend.mag);
79.2409 + mq = new MutableBigInteger();
79.2410 + r = mdividend.divide(ldivisor, mq);
79.2411 + isRemainderZero = (r == 0);
79.2412 + qsign = (ldivisor < 0) ? -bdividend.signum : bdividend.signum;
79.2413 + if (!isRemainderZero) {
79.2414 + if(needIncrement(ldivisor, roundingMode, qsign, mq, r)) {
79.2415 + mq.add(MutableBigInteger.ONE);
79.2416 + }
79.2417 + return mq.toBigDecimal(qsign, scale);
79.2418 + } else {
79.2419 + if (preferredScale != scale) {
79.2420 + long compactVal = mq.toCompactValue(qsign);
79.2421 + if(compactVal!=INFLATED) {
79.2422 + return createAndStripZerosToMatchScale(compactVal, scale, preferredScale);
79.2423 + }
79.2424 + BigInteger intVal = mq.toBigInteger(qsign);
79.2425 + return createAndStripZerosToMatchScale(intVal,scale, preferredScale);
79.2426 + } else {
79.2427 + return mq.toBigDecimal(qsign, scale);
79.2428 + }
79.2429 + }
79.2430 + }
79.2431 +
79.2432 + /**
79.2433 + * Tests if quotient has to be incremented according the roundingMode
79.2434 + */
79.2435 + private static boolean needIncrement(long ldivisor, int roundingMode,
79.2436 + int qsign, MutableBigInteger mq, long r) {
79.2437 + assert r != 0L;
79.2438 +
79.2439 + int cmpFracHalf;
79.2440 + if (r <= HALF_LONG_MIN_VALUE || r > HALF_LONG_MAX_VALUE) {
79.2441 + cmpFracHalf = 1; // 2 * r can't fit into long
79.2442 + } else {
79.2443 + cmpFracHalf = longCompareMagnitude(2 * r, ldivisor);
79.2444 + }
79.2445 +
79.2446 + return commonNeedIncrement(roundingMode, qsign, cmpFracHalf, mq.isOdd());
79.2447 + }
79.2448 +
79.2449 + /**
79.2450 + * Divides {@code BigInteger} value by {@code BigInteger} value and
79.2451 + * do rounding based on the passed in roundingMode.
79.2452 + */
79.2453 + private static BigInteger divideAndRound(BigInteger bdividend, BigInteger bdivisor, int roundingMode) {
79.2454 + boolean isRemainderZero; // record remainder is zero or not
79.2455 + int qsign; // quotient sign
79.2456 + // Descend into mutables for faster remainder checks
79.2457 + MutableBigInteger mdividend = new MutableBigInteger(bdividend.mag);
79.2458 + MutableBigInteger mq = new MutableBigInteger();
79.2459 + MutableBigInteger mdivisor = new MutableBigInteger(bdivisor.mag);
79.2460 + MutableBigInteger mr = mdividend.divide(mdivisor, mq);
79.2461 + isRemainderZero = mr.isZero();
79.2462 + qsign = (bdividend.signum != bdivisor.signum) ? -1 : 1;
79.2463 + if (!isRemainderZero) {
79.2464 + if (needIncrement(mdivisor, roundingMode, qsign, mq, mr)) {
79.2465 + mq.add(MutableBigInteger.ONE);
79.2466 + }
79.2467 + }
79.2468 + return mq.toBigInteger(qsign);
79.2469 + }
79.2470 +
79.2471 + /**
79.2472 + * Internally used for division operation for division {@code BigInteger}
79.2473 + * by {@code BigInteger}.
79.2474 + * The returned {@code BigDecimal} object is the quotient whose scale is set
79.2475 + * to the passed in scale. If the remainder is not zero, it will be rounded
79.2476 + * based on the passed in roundingMode. Also, if the remainder is zero and
79.2477 + * the last parameter, i.e. preferredScale is NOT equal to scale, the
79.2478 + * trailing zeros of the result is stripped to match the preferredScale.
79.2479 + */
79.2480 + private static BigDecimal divideAndRound(BigInteger bdividend, BigInteger bdivisor, int scale, int roundingMode,
79.2481 + int preferredScale) {
79.2482 + boolean isRemainderZero; // record remainder is zero or not
79.2483 + int qsign; // quotient sign
79.2484 + // Descend into mutables for faster remainder checks
79.2485 + MutableBigInteger mdividend = new MutableBigInteger(bdividend.mag);
79.2486 + MutableBigInteger mq = new MutableBigInteger();
79.2487 + MutableBigInteger mdivisor = new MutableBigInteger(bdivisor.mag);
79.2488 + MutableBigInteger mr = mdividend.divide(mdivisor, mq);
79.2489 + isRemainderZero = mr.isZero();
79.2490 + qsign = (bdividend.signum != bdivisor.signum) ? -1 : 1;
79.2491 + if (!isRemainderZero) {
79.2492 + if (needIncrement(mdivisor, roundingMode, qsign, mq, mr)) {
79.2493 + mq.add(MutableBigInteger.ONE);
79.2494 + }
79.2495 + return mq.toBigDecimal(qsign, scale);
79.2496 + } else {
79.2497 + if (preferredScale != scale) {
79.2498 + long compactVal = mq.toCompactValue(qsign);
79.2499 + if (compactVal != INFLATED) {
79.2500 + return createAndStripZerosToMatchScale(compactVal, scale, preferredScale);
79.2501 + }
79.2502 + BigInteger intVal = mq.toBigInteger(qsign);
79.2503 + return createAndStripZerosToMatchScale(intVal, scale, preferredScale);
79.2504 + } else {
79.2505 + return mq.toBigDecimal(qsign, scale);
79.2506 + }
79.2507 + }
79.2508 + }
79.2509 +
79.2510 + /**
79.2511 + * Tests if quotient has to be incremented according the roundingMode
79.2512 + */
79.2513 + private static boolean needIncrement(MutableBigInteger mdivisor, int roundingMode,
79.2514 + int qsign, MutableBigInteger mq, MutableBigInteger mr) {
79.2515 + assert !mr.isZero();
79.2516 + int cmpFracHalf = mr.compareHalf(mdivisor);
79.2517 + return commonNeedIncrement(roundingMode, qsign, cmpFracHalf, mq.isOdd());
79.2518 + }
79.2519 +
79.2520 + /**
79.2521 + * Remove insignificant trailing zeros from this
79.2522 + * {@code BigInteger} value until the preferred scale is reached or no
79.2523 + * more zeros can be removed. If the preferred scale is less than
79.2524 + * Integer.MIN_VALUE, all the trailing zeros will be removed.
79.2525 + *
79.2526 + * @return new {@code BigDecimal} with a scale possibly reduced
79.2527 + * to be closed to the preferred scale.
79.2528 + */
79.2529 + private static BigDecimal createAndStripZerosToMatchScale(BigInteger intVal, int scale, long preferredScale) {
79.2530 + BigInteger qr[]; // quotient-remainder pair
79.2531 + while (intVal.compareMagnitude(BigInteger.TEN) >= 0
79.2532 + && scale > preferredScale) {
79.2533 + if (intVal.testBit(0))
79.2534 + break; // odd number cannot end in 0
79.2535 + qr = intVal.divideAndRemainder(BigInteger.TEN);
79.2536 + if (qr[1].signum() != 0)
79.2537 + break; // non-0 remainder
79.2538 + intVal = qr[0];
79.2539 + scale = checkScale(intVal,(long) scale - 1); // could Overflow
79.2540 + }
79.2541 + return valueOf(intVal, scale, 0);
79.2542 + }
79.2543 +
79.2544 + /**
79.2545 + * Remove insignificant trailing zeros from this
79.2546 + * {@code long} value until the preferred scale is reached or no
79.2547 + * more zeros can be removed. If the preferred scale is less than
79.2548 + * Integer.MIN_VALUE, all the trailing zeros will be removed.
79.2549 + *
79.2550 + * @return new {@code BigDecimal} with a scale possibly reduced
79.2551 + * to be closed to the preferred scale.
79.2552 + */
79.2553 + private static BigDecimal createAndStripZerosToMatchScale(long compactVal, int scale, long preferredScale) {
79.2554 + while (Math.abs(compactVal) >= 10L && scale > preferredScale) {
79.2555 + if ((compactVal & 1L) != 0L)
79.2556 + break; // odd number cannot end in 0
79.2557 + long r = compactVal % 10L;
79.2558 + if (r != 0L)
79.2559 + break; // non-0 remainder
79.2560 + compactVal /= 10;
79.2561 + scale = checkScale(compactVal, (long) scale - 1); // could Overflow
79.2562 + }
79.2563 + return valueOf(compactVal, scale);
79.2564 + }
79.2565 +
79.2566 + private static BigDecimal stripZerosToMatchScale(BigInteger intVal, long intCompact, int scale, int preferredScale) {
79.2567 + if(intCompact!=INFLATED) {
79.2568 + return createAndStripZerosToMatchScale(intCompact, scale, preferredScale);
79.2569 + } else {
79.2570 + return createAndStripZerosToMatchScale(intVal==null ? INFLATED_BIGINT : intVal,
79.2571 + scale, preferredScale);
79.2572 + }
79.2573 + }
79.2574 +
79.2575 + /*
79.2576 + * returns INFLATED if oveflow
79.2577 + */
79.2578 + private static long add(long xs, long ys){
79.2579 + long sum = xs + ys;
79.2580 + // See "Hacker's Delight" section 2-12 for explanation of
79.2581 + // the overflow test.
79.2582 + if ( (((sum ^ xs) & (sum ^ ys))) >= 0L) { // not overflowed
79.2583 + return sum;
79.2584 + }
79.2585 + return INFLATED;
79.2586 + }
79.2587 +
79.2588 + private static BigDecimal add(long xs, long ys, int scale){
79.2589 + long sum = add(xs, ys);
79.2590 + if (sum!=INFLATED)
79.2591 + return BigDecimal.valueOf(sum, scale);
79.2592 + return new BigDecimal(BigInteger.valueOf(xs).add(ys), scale);
79.2593 + }
79.2594 +
79.2595 + private static BigDecimal add(final long xs, int scale1, final long ys, int scale2) {
79.2596 + long sdiff = (long) scale1 - scale2;
79.2597 + if (sdiff == 0) {
79.2598 + return add(xs, ys, scale1);
79.2599 + } else if (sdiff < 0) {
79.2600 + int raise = checkScale(xs,-sdiff);
79.2601 + long scaledX = longMultiplyPowerTen(xs, raise);
79.2602 + if (scaledX != INFLATED) {
79.2603 + return add(scaledX, ys, scale2);
79.2604 + } else {
79.2605 + BigInteger bigsum = bigMultiplyPowerTen(xs,raise).add(ys);
79.2606 + return ((xs^ys)>=0) ? // same sign test
79.2607 + new BigDecimal(bigsum, INFLATED, scale2, 0)
79.2608 + : valueOf(bigsum, scale2, 0);
79.2609 + }
79.2610 + } else {
79.2611 + int raise = checkScale(ys,sdiff);
79.2612 + long scaledY = longMultiplyPowerTen(ys, raise);
79.2613 + if (scaledY != INFLATED) {
79.2614 + return add(xs, scaledY, scale1);
79.2615 + } else {
79.2616 + BigInteger bigsum = bigMultiplyPowerTen(ys,raise).add(xs);
79.2617 + return ((xs^ys)>=0) ?
79.2618 + new BigDecimal(bigsum, INFLATED, scale1, 0)
79.2619 + : valueOf(bigsum, scale1, 0);
79.2620 + }
79.2621 + }
79.2622 + }
79.2623 +
79.2624 + private static BigDecimal add(final long xs, int scale1, BigInteger snd, int scale2) {
79.2625 + int rscale = scale1;
79.2626 + long sdiff = (long)rscale - scale2;
79.2627 + boolean sameSigns = (Long.signum(xs) == snd.signum);
79.2628 + BigInteger sum;
79.2629 + if (sdiff < 0) {
79.2630 + int raise = checkScale(xs,-sdiff);
79.2631 + rscale = scale2;
79.2632 + long scaledX = longMultiplyPowerTen(xs, raise);
79.2633 + if (scaledX == INFLATED) {
79.2634 + sum = snd.add(bigMultiplyPowerTen(xs,raise));
79.2635 + } else {
79.2636 + sum = snd.add(scaledX);
79.2637 + }
79.2638 + } else { //if (sdiff > 0) {
79.2639 + int raise = checkScale(snd,sdiff);
79.2640 + snd = bigMultiplyPowerTen(snd,raise);
79.2641 + sum = snd.add(xs);
79.2642 + }
79.2643 + return (sameSigns) ?
79.2644 + new BigDecimal(sum, INFLATED, rscale, 0) :
79.2645 + valueOf(sum, rscale, 0);
79.2646 + }
79.2647 +
79.2648 + private static BigDecimal add(BigInteger fst, int scale1, BigInteger snd, int scale2) {
79.2649 + int rscale = scale1;
79.2650 + long sdiff = (long)rscale - scale2;
79.2651 + if (sdiff != 0) {
79.2652 + if (sdiff < 0) {
79.2653 + int raise = checkScale(fst,-sdiff);
79.2654 + rscale = scale2;
79.2655 + fst = bigMultiplyPowerTen(fst,raise);
79.2656 + } else {
79.2657 + int raise = checkScale(snd,sdiff);
79.2658 + snd = bigMultiplyPowerTen(snd,raise);
79.2659 + }
79.2660 + }
79.2661 + BigInteger sum = fst.add(snd);
79.2662 + return (fst.signum == snd.signum) ?
79.2663 + new BigDecimal(sum, INFLATED, rscale, 0) :
79.2664 + valueOf(sum, rscale, 0);
79.2665 + }
79.2666 +
79.2667 + private static BigInteger bigMultiplyPowerTen(long value, int n) {
79.2668 + if (n <= 0)
79.2669 + return BigInteger.valueOf(value);
79.2670 + return bigTenToThe(n).multiply(value);
79.2671 + }
79.2672 +
79.2673 + private static BigInteger bigMultiplyPowerTen(BigInteger value, int n) {
79.2674 + if (n <= 0)
79.2675 + return value;
79.2676 + if(n<LONG_TEN_POWERS_TABLE.length) {
79.2677 + return value.multiply(LONG_TEN_POWERS_TABLE[n]);
79.2678 + }
79.2679 + return value.multiply(bigTenToThe(n));
79.2680 + }
79.2681 +
79.2682 + /**
79.2683 + * Returns a {@code BigDecimal} whose value is {@code (xs /
79.2684 + * ys)}, with rounding according to the context settings.
79.2685 + *
79.2686 + * Fast path - used only when (xscale <= yscale && yscale < 18
79.2687 + * && mc.presision<18) {
79.2688 + */
79.2689 + private static BigDecimal divideSmallFastPath(final long xs, int xscale,
79.2690 + final long ys, int yscale,
79.2691 + long preferredScale, MathContext mc) {
79.2692 + int mcp = mc.precision;
79.2693 + int roundingMode = mc.roundingMode.oldMode;
79.2694 +
79.2695 + assert (xscale <= yscale) && (yscale < 18) && (mcp < 18);
79.2696 + int xraise = yscale - xscale; // xraise >=0
79.2697 + long scaledX = (xraise==0) ? xs :
79.2698 + longMultiplyPowerTen(xs, xraise); // can't overflow here!
79.2699 + BigDecimal quotient;
79.2700 +
79.2701 + int cmp = longCompareMagnitude(scaledX, ys);
79.2702 + if(cmp > 0) { // satisfy constraint (b)
79.2703 + yscale -= 1; // [that is, divisor *= 10]
79.2704 + int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
79.2705 + if (checkScaleNonZero((long) mcp + yscale) > xscale) {
79.2706 + // assert newScale >= xscale
79.2707 + int raise = checkScaleNonZero((long) mcp + yscale - xscale);
79.2708 + long scaledXs;
79.2709 + if ((scaledXs = longMultiplyPowerTen(xs, raise)) == INFLATED) {
79.2710 + quotient = null;
79.2711 + if((mcp-1) >=0 && (mcp-1)<LONG_TEN_POWERS_TABLE.length) {
79.2712 + quotient = multiplyDivideAndRound(LONG_TEN_POWERS_TABLE[mcp-1], scaledX, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2713 + }
79.2714 + if(quotient==null) {
79.2715 + BigInteger rb = bigMultiplyPowerTen(scaledX,mcp-1);
79.2716 + quotient = divideAndRound(rb, ys,
79.2717 + scl, roundingMode, checkScaleNonZero(preferredScale));
79.2718 + }
79.2719 + } else {
79.2720 + quotient = divideAndRound(scaledXs, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2721 + }
79.2722 + } else {
79.2723 + int newScale = checkScaleNonZero((long) xscale - mcp);
79.2724 + // assert newScale >= yscale
79.2725 + if (newScale == yscale) { // easy case
79.2726 + quotient = divideAndRound(xs, ys, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2727 + } else {
79.2728 + int raise = checkScaleNonZero((long) newScale - yscale);
79.2729 + long scaledYs;
79.2730 + if ((scaledYs = longMultiplyPowerTen(ys, raise)) == INFLATED) {
79.2731 + BigInteger rb = bigMultiplyPowerTen(ys,raise);
79.2732 + quotient = divideAndRound(BigInteger.valueOf(xs),
79.2733 + rb, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2734 + } else {
79.2735 + quotient = divideAndRound(xs, scaledYs, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2736 + }
79.2737 + }
79.2738 + }
79.2739 + } else {
79.2740 + // abs(scaledX) <= abs(ys)
79.2741 + // result is "scaledX * 10^msp / ys"
79.2742 + int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
79.2743 + if(cmp==0) {
79.2744 + // abs(scaleX)== abs(ys) => result will be scaled 10^mcp + correct sign
79.2745 + quotient = roundedTenPower(((scaledX < 0) == (ys < 0)) ? 1 : -1, mcp, scl, checkScaleNonZero(preferredScale));
79.2746 + } else {
79.2747 + // abs(scaledX) < abs(ys)
79.2748 + long scaledXs;
79.2749 + if ((scaledXs = longMultiplyPowerTen(scaledX, mcp)) == INFLATED) {
79.2750 + quotient = null;
79.2751 + if(mcp<LONG_TEN_POWERS_TABLE.length) {
79.2752 + quotient = multiplyDivideAndRound(LONG_TEN_POWERS_TABLE[mcp], scaledX, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2753 + }
79.2754 + if(quotient==null) {
79.2755 + BigInteger rb = bigMultiplyPowerTen(scaledX,mcp);
79.2756 + quotient = divideAndRound(rb, ys,
79.2757 + scl, roundingMode, checkScaleNonZero(preferredScale));
79.2758 + }
79.2759 + } else {
79.2760 + quotient = divideAndRound(scaledXs, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2761 + }
79.2762 + }
79.2763 + }
79.2764 + // doRound, here, only affects 1000000000 case.
79.2765 + return doRound(quotient,mc);
79.2766 + }
79.2767 +
79.2768 + /**
79.2769 + * Returns a {@code BigDecimal} whose value is {@code (xs /
79.2770 + * ys)}, with rounding according to the context settings.
79.2771 + */
79.2772 + private static BigDecimal divide(final long xs, int xscale, final long ys, int yscale, long preferredScale, MathContext mc) {
79.2773 + int mcp = mc.precision;
79.2774 + if(xscale <= yscale && yscale < 18 && mcp<18) {
79.2775 + return divideSmallFastPath(xs, xscale, ys, yscale, preferredScale, mc);
79.2776 + }
79.2777 + if (compareMagnitudeNormalized(xs, xscale, ys, yscale) > 0) {// satisfy constraint (b)
79.2778 + yscale -= 1; // [that is, divisor *= 10]
79.2779 + }
79.2780 + int roundingMode = mc.roundingMode.oldMode;
79.2781 + // In order to find out whether the divide generates the exact result,
79.2782 + // we avoid calling the above divide method. 'quotient' holds the
79.2783 + // return BigDecimal object whose scale will be set to 'scl'.
79.2784 + int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
79.2785 + BigDecimal quotient;
79.2786 + if (checkScaleNonZero((long) mcp + yscale) > xscale) {
79.2787 + int raise = checkScaleNonZero((long) mcp + yscale - xscale);
79.2788 + long scaledXs;
79.2789 + if ((scaledXs = longMultiplyPowerTen(xs, raise)) == INFLATED) {
79.2790 + BigInteger rb = bigMultiplyPowerTen(xs,raise);
79.2791 + quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2792 + } else {
79.2793 + quotient = divideAndRound(scaledXs, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2794 + }
79.2795 + } else {
79.2796 + int newScale = checkScaleNonZero((long) xscale - mcp);
79.2797 + // assert newScale >= yscale
79.2798 + if (newScale == yscale) { // easy case
79.2799 + quotient = divideAndRound(xs, ys, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2800 + } else {
79.2801 + int raise = checkScaleNonZero((long) newScale - yscale);
79.2802 + long scaledYs;
79.2803 + if ((scaledYs = longMultiplyPowerTen(ys, raise)) == INFLATED) {
79.2804 + BigInteger rb = bigMultiplyPowerTen(ys,raise);
79.2805 + quotient = divideAndRound(BigInteger.valueOf(xs),
79.2806 + rb, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2807 + } else {
79.2808 + quotient = divideAndRound(xs, scaledYs, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2809 + }
79.2810 + }
79.2811 + }
79.2812 + // doRound, here, only affects 1000000000 case.
79.2813 + return doRound(quotient,mc);
79.2814 + }
79.2815 +
79.2816 + /**
79.2817 + * Returns a {@code BigDecimal} whose value is {@code (xs /
79.2818 + * ys)}, with rounding according to the context settings.
79.2819 + */
79.2820 + private static BigDecimal divide(BigInteger xs, int xscale, long ys, int yscale, long preferredScale, MathContext mc) {
79.2821 + // Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.2822 + if ((-compareMagnitudeNormalized(ys, yscale, xs, xscale)) > 0) {// satisfy constraint (b)
79.2823 + yscale -= 1; // [that is, divisor *= 10]
79.2824 + }
79.2825 + int mcp = mc.precision;
79.2826 + int roundingMode = mc.roundingMode.oldMode;
79.2827 +
79.2828 + // In order to find out whether the divide generates the exact result,
79.2829 + // we avoid calling the above divide method. 'quotient' holds the
79.2830 + // return BigDecimal object whose scale will be set to 'scl'.
79.2831 + BigDecimal quotient;
79.2832 + int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
79.2833 + if (checkScaleNonZero((long) mcp + yscale) > xscale) {
79.2834 + int raise = checkScaleNonZero((long) mcp + yscale - xscale);
79.2835 + BigInteger rb = bigMultiplyPowerTen(xs,raise);
79.2836 + quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2837 + } else {
79.2838 + int newScale = checkScaleNonZero((long) xscale - mcp);
79.2839 + // assert newScale >= yscale
79.2840 + if (newScale == yscale) { // easy case
79.2841 + quotient = divideAndRound(xs, ys, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2842 + } else {
79.2843 + int raise = checkScaleNonZero((long) newScale - yscale);
79.2844 + long scaledYs;
79.2845 + if ((scaledYs = longMultiplyPowerTen(ys, raise)) == INFLATED) {
79.2846 + BigInteger rb = bigMultiplyPowerTen(ys,raise);
79.2847 + quotient = divideAndRound(xs, rb, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2848 + } else {
79.2849 + quotient = divideAndRound(xs, scaledYs, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2850 + }
79.2851 + }
79.2852 + }
79.2853 + // doRound, here, only affects 1000000000 case.
79.2854 + return doRound(quotient, mc);
79.2855 + }
79.2856 +
79.2857 + /**
79.2858 + * Returns a {@code BigDecimal} whose value is {@code (xs /
79.2859 + * ys)}, with rounding according to the context settings.
79.2860 + */
79.2861 + private static BigDecimal divide(long xs, int xscale, BigInteger ys, int yscale, long preferredScale, MathContext mc) {
79.2862 + // Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.2863 + if (compareMagnitudeNormalized(xs, xscale, ys, yscale) > 0) {// satisfy constraint (b)
79.2864 + yscale -= 1; // [that is, divisor *= 10]
79.2865 + }
79.2866 + int mcp = mc.precision;
79.2867 + int roundingMode = mc.roundingMode.oldMode;
79.2868 +
79.2869 + // In order to find out whether the divide generates the exact result,
79.2870 + // we avoid calling the above divide method. 'quotient' holds the
79.2871 + // return BigDecimal object whose scale will be set to 'scl'.
79.2872 + BigDecimal quotient;
79.2873 + int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
79.2874 + if (checkScaleNonZero((long) mcp + yscale) > xscale) {
79.2875 + int raise = checkScaleNonZero((long) mcp + yscale - xscale);
79.2876 + BigInteger rb = bigMultiplyPowerTen(xs,raise);
79.2877 + quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2878 + } else {
79.2879 + int newScale = checkScaleNonZero((long) xscale - mcp);
79.2880 + int raise = checkScaleNonZero((long) newScale - yscale);
79.2881 + BigInteger rb = bigMultiplyPowerTen(ys,raise);
79.2882 + quotient = divideAndRound(BigInteger.valueOf(xs), rb, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2883 + }
79.2884 + // doRound, here, only affects 1000000000 case.
79.2885 + return doRound(quotient, mc);
79.2886 + }
79.2887 +
79.2888 + /**
79.2889 + * Returns a {@code BigDecimal} whose value is {@code (xs /
79.2890 + * ys)}, with rounding according to the context settings.
79.2891 + */
79.2892 + private static BigDecimal divide(BigInteger xs, int xscale, BigInteger ys, int yscale, long preferredScale, MathContext mc) {
79.2893 + // Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.2894 + if (compareMagnitudeNormalized(xs, xscale, ys, yscale) > 0) {// satisfy constraint (b)
79.2895 + yscale -= 1; // [that is, divisor *= 10]
79.2896 + }
79.2897 + int mcp = mc.precision;
79.2898 + int roundingMode = mc.roundingMode.oldMode;
79.2899 +
79.2900 + // In order to find out whether the divide generates the exact result,
79.2901 + // we avoid calling the above divide method. 'quotient' holds the
79.2902 + // return BigDecimal object whose scale will be set to 'scl'.
79.2903 + BigDecimal quotient;
79.2904 + int scl = checkScaleNonZero(preferredScale + yscale - xscale + mcp);
79.2905 + if (checkScaleNonZero((long) mcp + yscale) > xscale) {
79.2906 + int raise = checkScaleNonZero((long) mcp + yscale - xscale);
79.2907 + BigInteger rb = bigMultiplyPowerTen(xs,raise);
79.2908 + quotient = divideAndRound(rb, ys, scl, roundingMode, checkScaleNonZero(preferredScale));
79.2909 + } else {
79.2910 + int newScale = checkScaleNonZero((long) xscale - mcp);
79.2911 + int raise = checkScaleNonZero((long) newScale - yscale);
79.2912 + BigInteger rb = bigMultiplyPowerTen(ys,raise);
79.2913 + quotient = divideAndRound(xs, rb, scl, roundingMode,checkScaleNonZero(preferredScale));
79.2914 + }
79.2915 + // doRound, here, only affects 1000000000 case.
79.2916 + return doRound(quotient, mc);
79.2917 + }
79.2918 +
79.2919 + /*
79.2920 + * performs divideAndRound for (dividend0*dividend1, divisor)
79.2921 + * returns null if quotient can't fit into long value;
79.2922 + */
79.2923 + private static BigDecimal multiplyDivideAndRound(long dividend0, long dividend1, long divisor, int scale, int roundingMode,
79.2924 + int preferredScale) {
79.2925 + int qsign = Long.signum(dividend0)*Long.signum(dividend1)*Long.signum(divisor);
79.2926 + dividend0 = Math.abs(dividend0);
79.2927 + dividend1 = Math.abs(dividend1);
79.2928 + divisor = Math.abs(divisor);
79.2929 + // multiply dividend0 * dividend1
79.2930 + long d0_hi = dividend0 >>> 32;
79.2931 + long d0_lo = dividend0 & LONG_MASK;
79.2932 + long d1_hi = dividend1 >>> 32;
79.2933 + long d1_lo = dividend1 & LONG_MASK;
79.2934 + long product = d0_lo * d1_lo;
79.2935 + long d0 = product & LONG_MASK;
79.2936 + long d1 = product >>> 32;
79.2937 + product = d0_hi * d1_lo + d1;
79.2938 + d1 = product & LONG_MASK;
79.2939 + long d2 = product >>> 32;
79.2940 + product = d0_lo * d1_hi + d1;
79.2941 + d1 = product & LONG_MASK;
79.2942 + d2 += product >>> 32;
79.2943 + long d3 = d2>>>32;
79.2944 + d2 &= LONG_MASK;
79.2945 + product = d0_hi*d1_hi + d2;
79.2946 + d2 = product & LONG_MASK;
79.2947 + d3 = ((product>>>32) + d3) & LONG_MASK;
79.2948 + final long dividendHi = make64(d3,d2);
79.2949 + final long dividendLo = make64(d1,d0);
79.2950 + // divide
79.2951 + return divideAndRound128(dividendHi, dividendLo, divisor, qsign, scale, roundingMode, preferredScale);
79.2952 + }
79.2953 +
79.2954 + private static final long DIV_NUM_BASE = (1L<<32); // Number base (32 bits).
79.2955 +
79.2956 + /*
79.2957 + * divideAndRound 128-bit value by long divisor.
79.2958 + * returns null if quotient can't fit into long value;
79.2959 + * Specialized version of Knuth's division
79.2960 + */
79.2961 + private static BigDecimal divideAndRound128(final long dividendHi, final long dividendLo, long divisor, int sign,
79.2962 + int scale, int roundingMode, int preferredScale) {
79.2963 + if (dividendHi >= divisor) {
79.2964 + return null;
79.2965 + }
79.2966 + final int shift = Long.numberOfLeadingZeros(divisor);
79.2967 + divisor <<= shift;
79.2968 +
79.2969 + final long v1 = divisor >>> 32;
79.2970 + final long v0 = divisor & LONG_MASK;
79.2971 +
79.2972 + long q1, q0;
79.2973 + long r_tmp;
79.2974 +
79.2975 + long tmp = dividendLo << shift;
79.2976 + long u1 = tmp >>> 32;
79.2977 + long u0 = tmp & LONG_MASK;
79.2978 +
79.2979 + tmp = (dividendHi << shift) | (dividendLo >>> 64 - shift);
79.2980 + long u2 = tmp & LONG_MASK;
79.2981 + tmp = divWord(tmp,v1);
79.2982 + q1 = tmp & LONG_MASK;
79.2983 + r_tmp = tmp >>> 32;
79.2984 + while(q1 >= DIV_NUM_BASE || unsignedLongCompare(q1*v0, make64(r_tmp, u1))) {
79.2985 + q1--;
79.2986 + r_tmp += v1;
79.2987 + if (r_tmp >= DIV_NUM_BASE)
79.2988 + break;
79.2989 + }
79.2990 + tmp = mulsub(u2,u1,v1,v0,q1);
79.2991 + u1 = tmp & LONG_MASK;
79.2992 + tmp = divWord(tmp,v1);
79.2993 + q0 = tmp & LONG_MASK;
79.2994 + r_tmp = tmp >>> 32;
79.2995 + while(q0 >= DIV_NUM_BASE || unsignedLongCompare(q0*v0,make64(r_tmp,u0))) {
79.2996 + q0--;
79.2997 + r_tmp += v1;
79.2998 + if (r_tmp >= DIV_NUM_BASE)
79.2999 + break;
79.3000 + }
79.3001 + if((int)q1 < 0) {
79.3002 + // result (which is positive and unsigned here)
79.3003 + // can't fit into long due to sign bit is used for value
79.3004 + MutableBigInteger mq = new MutableBigInteger(new int[]{(int)q1, (int)q0});
79.3005 + if (roundingMode == ROUND_DOWN && scale == preferredScale) {
79.3006 + return mq.toBigDecimal(sign, scale);
79.3007 + }
79.3008 + long r = mulsub(u1, u0, v1, v0, q0) >>> shift;
79.3009 + if (r != 0) {
79.3010 + if(needIncrement(divisor >>> shift, roundingMode, sign, mq, r)){
79.3011 + mq.add(MutableBigInteger.ONE);
79.3012 + }
79.3013 + return mq.toBigDecimal(sign, scale);
79.3014 + } else {
79.3015 + if (preferredScale != scale) {
79.3016 + BigInteger intVal = mq.toBigInteger(sign);
79.3017 + return createAndStripZerosToMatchScale(intVal,scale, preferredScale);
79.3018 + } else {
79.3019 + return mq.toBigDecimal(sign, scale);
79.3020 + }
79.3021 + }
79.3022 + }
79.3023 + long q = make64(q1,q0);
79.3024 + q*=sign;
79.3025 + if (roundingMode == ROUND_DOWN && scale == preferredScale)
79.3026 + return valueOf(q, scale);
79.3027 + long r = mulsub(u1, u0, v1, v0, q0) >>> shift;
79.3028 + if (r != 0) {
79.3029 + boolean increment = needIncrement(divisor >>> shift, roundingMode, sign, q, r);
79.3030 + return valueOf((increment ? q + sign : q), scale);
79.3031 + } else {
79.3032 + if (preferredScale != scale) {
79.3033 + return createAndStripZerosToMatchScale(q, scale, preferredScale);
79.3034 + } else {
79.3035 + return valueOf(q, scale);
79.3036 + }
79.3037 + }
79.3038 + }
79.3039 +
79.3040 + /*
79.3041 + * calculate divideAndRound for ldividend*10^raise / divisor
79.3042 + * when abs(dividend)==abs(divisor);
79.3043 + */
79.3044 + private static BigDecimal roundedTenPower(int qsign, int raise, int scale, int preferredScale) {
79.3045 + if (scale > preferredScale) {
79.3046 + int diff = scale - preferredScale;
79.3047 + if(diff < raise) {
79.3048 + return scaledTenPow(raise - diff, qsign, preferredScale);
79.3049 + } else {
79.3050 + return valueOf(qsign,scale-raise);
79.3051 + }
79.3052 + } else {
79.3053 + return scaledTenPow(raise, qsign, scale);
79.3054 + }
79.3055 + }
79.3056 +
79.3057 + static BigDecimal scaledTenPow(int n, int sign, int scale) {
79.3058 + if (n < LONG_TEN_POWERS_TABLE.length)
79.3059 + return valueOf(sign*LONG_TEN_POWERS_TABLE[n],scale);
79.3060 + else {
79.3061 + BigInteger unscaledVal = bigTenToThe(n);
79.3062 + if(sign==-1) {
79.3063 + unscaledVal = unscaledVal.negate();
79.3064 + }
79.3065 + return new BigDecimal(unscaledVal, INFLATED, scale, n+1);
79.3066 + }
79.3067 + }
79.3068 +
79.3069 + private static long divWord(long n, long dLong) {
79.3070 + long r;
79.3071 + long q;
79.3072 + if (dLong == 1) {
79.3073 + q = (int)n;
79.3074 + return (q & LONG_MASK);
79.3075 + }
79.3076 + // Approximate the quotient and remainder
79.3077 + q = (n >>> 1) / (dLong >>> 1);
79.3078 + r = n - q*dLong;
79.3079 +
79.3080 + // Correct the approximation
79.3081 + while (r < 0) {
79.3082 + r += dLong;
79.3083 + q--;
79.3084 + }
79.3085 + while (r >= dLong) {
79.3086 + r -= dLong;
79.3087 + q++;
79.3088 + }
79.3089 + // n - q*dlong == r && 0 <= r <dLong, hence we're done.
79.3090 + return (r << 32) | (q & LONG_MASK);
79.3091 + }
79.3092 +
79.3093 + private static long make64(long hi, long lo) {
79.3094 + return hi<<32 | lo;
79.3095 + }
79.3096 +
79.3097 + private static long mulsub(long u1, long u0, final long v1, final long v0, long q0) {
79.3098 + long tmp = u0 - q0*v0;
79.3099 + return make64(u1 + (tmp>>>32) - q0*v1,tmp & LONG_MASK);
79.3100 + }
79.3101 +
79.3102 + private static boolean unsignedLongCompare(long one, long two) {
79.3103 + return (one+Long.MIN_VALUE) > (two+Long.MIN_VALUE);
79.3104 + }
79.3105 +
79.3106 + private static boolean unsignedLongCompareEq(long one, long two) {
79.3107 + return (one+Long.MIN_VALUE) >= (two+Long.MIN_VALUE);
79.3108 + }
79.3109 +
79.3110 +
79.3111 + // Compare Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.3112 + private static int compareMagnitudeNormalized(long xs, int xscale, long ys, int yscale) {
79.3113 + // assert xs!=0 && ys!=0
79.3114 + int sdiff = xscale - yscale;
79.3115 + if (sdiff != 0) {
79.3116 + if (sdiff < 0) {
79.3117 + xs = longMultiplyPowerTen(xs, -sdiff);
79.3118 + } else { // sdiff > 0
79.3119 + ys = longMultiplyPowerTen(ys, sdiff);
79.3120 + }
79.3121 + }
79.3122 + if (xs != INFLATED)
79.3123 + return (ys != INFLATED) ? longCompareMagnitude(xs, ys) : -1;
79.3124 + else
79.3125 + return 1;
79.3126 + }
79.3127 +
79.3128 + // Compare Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.3129 + private static int compareMagnitudeNormalized(long xs, int xscale, BigInteger ys, int yscale) {
79.3130 + // assert "ys can't be represented as long"
79.3131 + if (xs == 0)
79.3132 + return -1;
79.3133 + int sdiff = xscale - yscale;
79.3134 + if (sdiff < 0) {
79.3135 + if (longMultiplyPowerTen(xs, -sdiff) == INFLATED ) {
79.3136 + return bigMultiplyPowerTen(xs, -sdiff).compareMagnitude(ys);
79.3137 + }
79.3138 + }
79.3139 + return -1;
79.3140 + }
79.3141 +
79.3142 + // Compare Normalize dividend & divisor so that both fall into [0.1, 0.999...]
79.3143 + private static int compareMagnitudeNormalized(BigInteger xs, int xscale, BigInteger ys, int yscale) {
79.3144 + int sdiff = xscale - yscale;
79.3145 + if (sdiff < 0) {
79.3146 + return bigMultiplyPowerTen(xs, -sdiff).compareMagnitude(ys);
79.3147 + } else { // sdiff >= 0
79.3148 + return xs.compareMagnitude(bigMultiplyPowerTen(ys, sdiff));
79.3149 + }
79.3150 + }
79.3151 +
79.3152 + private static long multiply(long x, long y){
79.3153 + long product = x * y;
79.3154 + long ax = Math.abs(x);
79.3155 + long ay = Math.abs(y);
79.3156 + if (((ax | ay) >>> 31 == 0) || (y == 0) || (product / y == x)){
79.3157 + return product;
79.3158 + }
79.3159 + return INFLATED;
79.3160 + }
79.3161 +
79.3162 + private static BigDecimal multiply(long x, long y, int scale) {
79.3163 + long product = multiply(x, y);
79.3164 + if(product!=INFLATED) {
79.3165 + return valueOf(product,scale);
79.3166 + }
79.3167 + return new BigDecimal(BigInteger.valueOf(x).multiply(y),INFLATED,scale,0);
79.3168 + }
79.3169 +
79.3170 + private static BigDecimal multiply(long x, BigInteger y, int scale) {
79.3171 + if(x==0) {
79.3172 + return zeroValueOf(scale);
79.3173 + }
79.3174 + return new BigDecimal(y.multiply(x),INFLATED,scale,0);
79.3175 + }
79.3176 +
79.3177 + private static BigDecimal multiply(BigInteger x, BigInteger y, int scale) {
79.3178 + return new BigDecimal(x.multiply(y),INFLATED,scale,0);
79.3179 + }
79.3180 +
79.3181 + /**
79.3182 + * Multiplies two long values and rounds according {@code MathContext}
79.3183 + */
79.3184 + private static BigDecimal multiplyAndRound(long x, long y, int scale, MathContext mc) {
79.3185 + long product = multiply(x, y);
79.3186 + if(product!=INFLATED) {
79.3187 + return doRound(product, scale, mc);
79.3188 + }
79.3189 + // attempt to do it in 128 bits
79.3190 + int rsign = 1;
79.3191 + if(x < 0) {
79.3192 + x = -x;
79.3193 + rsign = -1;
79.3194 + }
79.3195 + if(y < 0) {
79.3196 + y = -y;
79.3197 + rsign *= -1;
79.3198 + }
79.3199 + // multiply dividend0 * dividend1
79.3200 + long m0_hi = x >>> 32;
79.3201 + long m0_lo = x & LONG_MASK;
79.3202 + long m1_hi = y >>> 32;
79.3203 + long m1_lo = y & LONG_MASK;
79.3204 + product = m0_lo * m1_lo;
79.3205 + long m0 = product & LONG_MASK;
79.3206 + long m1 = product >>> 32;
79.3207 + product = m0_hi * m1_lo + m1;
79.3208 + m1 = product & LONG_MASK;
79.3209 + long m2 = product >>> 32;
79.3210 + product = m0_lo * m1_hi + m1;
79.3211 + m1 = product & LONG_MASK;
79.3212 + m2 += product >>> 32;
79.3213 + long m3 = m2>>>32;
79.3214 + m2 &= LONG_MASK;
79.3215 + product = m0_hi*m1_hi + m2;
79.3216 + m2 = product & LONG_MASK;
79.3217 + m3 = ((product>>>32) + m3) & LONG_MASK;
79.3218 + final long mHi = make64(m3,m2);
79.3219 + final long mLo = make64(m1,m0);
79.3220 + BigDecimal res = doRound128(mHi, mLo, rsign, scale, mc);
79.3221 + if(res!=null) {
79.3222 + return res;
79.3223 + }
79.3224 + res = new BigDecimal(BigInteger.valueOf(x).multiply(y*rsign), INFLATED, scale, 0);
79.3225 + return doRound(res,mc);
79.3226 + }
79.3227 +
79.3228 + private static BigDecimal multiplyAndRound(long x, BigInteger y, int scale, MathContext mc) {
79.3229 + if(x==0) {
79.3230 + return zeroValueOf(scale);
79.3231 + }
79.3232 + return doRound(y.multiply(x), scale, mc);
79.3233 + }
79.3234 +
79.3235 + private static BigDecimal multiplyAndRound(BigInteger x, BigInteger y, int scale, MathContext mc) {
79.3236 + return doRound(x.multiply(y), scale, mc);
79.3237 + }
79.3238 +
79.3239 + /**
79.3240 + * rounds 128-bit value according {@code MathContext}
79.3241 + * returns null if result can't be repsented as compact BigDecimal.
79.3242 + */
79.3243 + private static BigDecimal doRound128(long hi, long lo, int sign, int scale, MathContext mc) {
79.3244 + int mcp = mc.precision;
79.3245 + int drop;
79.3246 + BigDecimal res = null;
79.3247 + if(((drop = precision(hi, lo) - mcp) > 0)&&(drop<LONG_TEN_POWERS_TABLE.length)) {
79.3248 + scale = checkScaleNonZero((long)scale - drop);
79.3249 + res = divideAndRound128(hi, lo, LONG_TEN_POWERS_TABLE[drop], sign, scale, mc.roundingMode.oldMode, scale);
79.3250 + }
79.3251 + if(res!=null) {
79.3252 + return doRound(res,mc);
79.3253 + }
79.3254 + return null;
79.3255 + }
79.3256 +
79.3257 + private static final long[][] LONGLONG_TEN_POWERS_TABLE = {
79.3258 + { 0L, 0x8AC7230489E80000L }, //10^19
79.3259 + { 0x5L, 0x6bc75e2d63100000L }, //10^20
79.3260 + { 0x36L, 0x35c9adc5dea00000L }, //10^21
79.3261 + { 0x21eL, 0x19e0c9bab2400000L }, //10^22
79.3262 + { 0x152dL, 0x02c7e14af6800000L }, //10^23
79.3263 + { 0xd3c2L, 0x1bcecceda1000000L }, //10^24
79.3264 + { 0x84595L, 0x161401484a000000L }, //10^25
79.3265 + { 0x52b7d2L, 0xdcc80cd2e4000000L }, //10^26
79.3266 + { 0x33b2e3cL, 0x9fd0803ce8000000L }, //10^27
79.3267 + { 0x204fce5eL, 0x3e25026110000000L }, //10^28
79.3268 + { 0x1431e0faeL, 0x6d7217caa0000000L }, //10^29
79.3269 + { 0xc9f2c9cd0L, 0x4674edea40000000L }, //10^30
79.3270 + { 0x7e37be2022L, 0xc0914b2680000000L }, //10^31
79.3271 + { 0x4ee2d6d415bL, 0x85acef8100000000L }, //10^32
79.3272 + { 0x314dc6448d93L, 0x38c15b0a00000000L }, //10^33
79.3273 + { 0x1ed09bead87c0L, 0x378d8e6400000000L }, //10^34
79.3274 + { 0x13426172c74d82L, 0x2b878fe800000000L }, //10^35
79.3275 + { 0xc097ce7bc90715L, 0xb34b9f1000000000L }, //10^36
79.3276 + { 0x785ee10d5da46d9L, 0x00f436a000000000L }, //10^37
79.3277 + { 0x4b3b4ca85a86c47aL, 0x098a224000000000L }, //10^38
79.3278 + };
79.3279 +
79.3280 + /*
79.3281 + * returns precision of 128-bit value
79.3282 + */
79.3283 + private static int precision(long hi, long lo){
79.3284 + if(hi==0) {
79.3285 + if(lo>=0) {
79.3286 + return longDigitLength(lo);
79.3287 + }
79.3288 + return (unsignedLongCompareEq(lo, LONGLONG_TEN_POWERS_TABLE[0][1])) ? 20 : 19;
79.3289 + // 0x8AC7230489E80000L = unsigned 2^19
79.3290 + }
79.3291 + int r = ((128 - Long.numberOfLeadingZeros(hi) + 1) * 1233) >>> 12;
79.3292 + int idx = r-19;
79.3293 + return (idx >= LONGLONG_TEN_POWERS_TABLE.length || longLongCompareMagnitude(hi, lo,
79.3294 + LONGLONG_TEN_POWERS_TABLE[idx][0], LONGLONG_TEN_POWERS_TABLE[idx][1])) ? r : r + 1;
79.3295 + }
79.3296 +
79.3297 + /*
79.3298 + * returns true if 128 bit number <hi0,lo0> is less then <hi1,lo1>
79.3299 + * hi0 & hi1 should be non-negative
79.3300 + */
79.3301 + private static boolean longLongCompareMagnitude(long hi0, long lo0, long hi1, long lo1) {
79.3302 + if(hi0!=hi1) {
79.3303 + return hi0<hi1;
79.3304 + }
79.3305 + return (lo0+Long.MIN_VALUE) <(lo1+Long.MIN_VALUE);
79.3306 + }
79.3307 +
79.3308 + private static BigDecimal divide(long dividend, int dividendScale, long divisor, int divisorScale, int scale, int roundingMode) {
79.3309 + if (checkScale(dividend,(long)scale + divisorScale) > dividendScale) {
79.3310 + int newScale = scale + divisorScale;
79.3311 + int raise = newScale - dividendScale;
79.3312 + if(raise<LONG_TEN_POWERS_TABLE.length) {
79.3313 + long xs = dividend;
79.3314 + if ((xs = longMultiplyPowerTen(xs, raise)) != INFLATED) {
79.3315 + return divideAndRound(xs, divisor, scale, roundingMode, scale);
79.3316 + }
79.3317 + BigDecimal q = multiplyDivideAndRound(LONG_TEN_POWERS_TABLE[raise], dividend, divisor, scale, roundingMode, scale);
79.3318 + if(q!=null) {
79.3319 + return q;
79.3320 + }
79.3321 + }
79.3322 + BigInteger scaledDividend = bigMultiplyPowerTen(dividend, raise);
79.3323 + return divideAndRound(scaledDividend, divisor, scale, roundingMode, scale);
79.3324 + } else {
79.3325 + int newScale = checkScale(divisor,(long)dividendScale - scale);
79.3326 + int raise = newScale - divisorScale;
79.3327 + if(raise<LONG_TEN_POWERS_TABLE.length) {
79.3328 + long ys = divisor;
79.3329 + if ((ys = longMultiplyPowerTen(ys, raise)) != INFLATED) {
79.3330 + return divideAndRound(dividend, ys, scale, roundingMode, scale);
79.3331 + }
79.3332 + }
79.3333 + BigInteger scaledDivisor = bigMultiplyPowerTen(divisor, raise);
79.3334 + return divideAndRound(BigInteger.valueOf(dividend), scaledDivisor, scale, roundingMode, scale);
79.3335 + }
79.3336 + }
79.3337 +
79.3338 + private static BigDecimal divide(BigInteger dividend, int dividendScale, long divisor, int divisorScale, int scale, int roundingMode) {
79.3339 + if (checkScale(dividend,(long)scale + divisorScale) > dividendScale) {
79.3340 + int newScale = scale + divisorScale;
79.3341 + int raise = newScale - dividendScale;
79.3342 + BigInteger scaledDividend = bigMultiplyPowerTen(dividend, raise);
79.3343 + return divideAndRound(scaledDividend, divisor, scale, roundingMode, scale);
79.3344 + } else {
79.3345 + int newScale = checkScale(divisor,(long)dividendScale - scale);
79.3346 + int raise = newScale - divisorScale;
79.3347 + if(raise<LONG_TEN_POWERS_TABLE.length) {
79.3348 + long ys = divisor;
79.3349 + if ((ys = longMultiplyPowerTen(ys, raise)) != INFLATED) {
79.3350 + return divideAndRound(dividend, ys, scale, roundingMode, scale);
79.3351 + }
79.3352 + }
79.3353 + BigInteger scaledDivisor = bigMultiplyPowerTen(divisor, raise);
79.3354 + return divideAndRound(dividend, scaledDivisor, scale, roundingMode, scale);
79.3355 + }
79.3356 + }
79.3357 +
79.3358 + private static BigDecimal divide(long dividend, int dividendScale, BigInteger divisor, int divisorScale, int scale, int roundingMode) {
79.3359 + if (checkScale(dividend,(long)scale + divisorScale) > dividendScale) {
79.3360 + int newScale = scale + divisorScale;
79.3361 + int raise = newScale - dividendScale;
79.3362 + BigInteger scaledDividend = bigMultiplyPowerTen(dividend, raise);
79.3363 + return divideAndRound(scaledDividend, divisor, scale, roundingMode, scale);
79.3364 + } else {
79.3365 + int newScale = checkScale(divisor,(long)dividendScale - scale);
79.3366 + int raise = newScale - divisorScale;
79.3367 + BigInteger scaledDivisor = bigMultiplyPowerTen(divisor, raise);
79.3368 + return divideAndRound(BigInteger.valueOf(dividend), scaledDivisor, scale, roundingMode, scale);
79.3369 + }
79.3370 + }
79.3371 +
79.3372 + private static BigDecimal divide(BigInteger dividend, int dividendScale, BigInteger divisor, int divisorScale, int scale, int roundingMode) {
79.3373 + if (checkScale(dividend,(long)scale + divisorScale) > dividendScale) {
79.3374 + int newScale = scale + divisorScale;
79.3375 + int raise = newScale - dividendScale;
79.3376 + BigInteger scaledDividend = bigMultiplyPowerTen(dividend, raise);
79.3377 + return divideAndRound(scaledDividend, divisor, scale, roundingMode, scale);
79.3378 + } else {
79.3379 + int newScale = checkScale(divisor,(long)dividendScale - scale);
79.3380 + int raise = newScale - divisorScale;
79.3381 + BigInteger scaledDivisor = bigMultiplyPowerTen(divisor, raise);
79.3382 + return divideAndRound(dividend, scaledDivisor, scale, roundingMode, scale);
79.3383 + }
79.3384 + }
79.3385 +
79.3386 }
80.1 --- a/src/share/classes/java/math/BigInteger.java Thu Sep 15 18:53:28 2011 -0700
80.2 +++ b/src/share/classes/java/math/BigInteger.java Mon Sep 19 19:40:59 2011 -0700
80.3 @@ -1,5 +1,5 @@
80.4 /*
80.5 - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved.
80.6 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
80.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80.8 *
80.9 * This code is free software; you can redistribute it and/or modify it
80.10 @@ -31,6 +31,7 @@
80.11
80.12 import java.util.Random;
80.13 import java.io.*;
80.14 +import java.util.Arrays;
80.15
80.16 /**
80.17 * Immutable arbitrary-precision integers. All operations behave as if
80.18 @@ -353,27 +354,17 @@
80.19 mag = trustedStripLeadingZeroInts(magnitude);
80.20 }
80.21
80.22 - // Constructs a new BigInteger using a char array with radix=10
80.23 - BigInteger(char[] val) {
80.24 + /*
80.25 + * Constructs a new BigInteger using a char array with radix=10.
80.26 + * Sign is precalculated outside and not allowed in the val.
80.27 + */
80.28 + BigInteger(char[] val, int sign, int len) {
80.29 int cursor = 0, numDigits;
80.30 - int len = val.length;
80.31 -
80.32 - // Check for leading minus sign
80.33 - int sign = 1;
80.34 - if (val[0] == '-') {
80.35 - if (len == 1)
80.36 - throw new NumberFormatException("Zero length BigInteger");
80.37 - sign = -1;
80.38 - cursor = 1;
80.39 - } else if (val[0] == '+') {
80.40 - if (len == 1)
80.41 - throw new NumberFormatException("Zero length BigInteger");
80.42 - cursor = 1;
80.43 +
80.44 + // Skip leading zeros and compute number of digits in magnitude
80.45 + while (cursor < len && Character.digit(val[cursor], 10) == 0) {
80.46 + cursor++;
80.47 }
80.48 -
80.49 - // Skip leading zeros and compute number of digits in magnitude
80.50 - while (cursor < len && Character.digit(val[cursor], 10) == 0)
80.51 - cursor++;
80.52 if (cursor == len) {
80.53 signum = 0;
80.54 mag = ZERO.mag;
80.55 @@ -382,7 +373,6 @@
80.56
80.57 numDigits = len - cursor;
80.58 signum = sign;
80.59 -
80.60 // Pre-allocate array of expected size
80.61 int numWords;
80.62 if (len < 10) {
80.63 @@ -1058,6 +1048,73 @@
80.64 }
80.65
80.66 /**
80.67 + * Package private methods used by BigDecimal code to add a BigInteger
80.68 + * with a long. Assumes val is not equal to INFLATED.
80.69 + */
80.70 + BigInteger add(long val) {
80.71 + if (val == 0)
80.72 + return this;
80.73 + if (signum == 0)
80.74 + return valueOf(val);
80.75 + if (Long.signum(val) == signum)
80.76 + return new BigInteger(add(mag, Math.abs(val)), signum);
80.77 + int cmp = compareMagnitude(val);
80.78 + if (cmp == 0)
80.79 + return ZERO;
80.80 + int[] resultMag = (cmp > 0 ? subtract(mag, Math.abs(val)) : subtract(Math.abs(val), mag));
80.81 + resultMag = trustedStripLeadingZeroInts(resultMag);
80.82 + return new BigInteger(resultMag, cmp == signum ? 1 : -1);
80.83 + }
80.84 +
80.85 + /**
80.86 + * Adds the contents of the int array x and long value val. This
80.87 + * method allocates a new int array to hold the answer and returns
80.88 + * a reference to that array. Assumes x.length > 0 and val is
80.89 + * non-negative
80.90 + */
80.91 + private static int[] add(int[] x, long val) {
80.92 + int[] y;
80.93 + long sum = 0;
80.94 + int xIndex = x.length;
80.95 + int[] result;
80.96 + int highWord = (int)(val >>> 32);
80.97 + if (highWord==0) {
80.98 + result = new int[xIndex];
80.99 + sum = (x[--xIndex] & LONG_MASK) + val;
80.100 + result[xIndex] = (int)sum;
80.101 + } else {
80.102 + if (xIndex == 1) {
80.103 + result = new int[2];
80.104 + sum = val + (x[0] & LONG_MASK);
80.105 + result[1] = (int)sum;
80.106 + result[0] = (int)(sum >>> 32);
80.107 + return result;
80.108 + } else {
80.109 + result = new int[xIndex];
80.110 + sum = (x[--xIndex] & LONG_MASK) + (val & LONG_MASK);
80.111 + result[xIndex] = (int)sum;
80.112 + sum = (x[--xIndex] & LONG_MASK) + (highWord & LONG_MASK) + (sum >>> 32);
80.113 + result[xIndex] = (int)sum;
80.114 + }
80.115 + }
80.116 + // Copy remainder of longer number while carry propagation is required
80.117 + boolean carry = (sum >>> 32 != 0);
80.118 + while (xIndex > 0 && carry)
80.119 + carry = ((result[--xIndex] = x[xIndex] + 1) == 0);
80.120 + // Copy remainder of longer number
80.121 + while (xIndex > 0)
80.122 + result[--xIndex] = x[xIndex];
80.123 + // Grow result if necessary
80.124 + if (carry) {
80.125 + int bigger[] = new int[result.length + 1];
80.126 + System.arraycopy(result, 0, bigger, 1, result.length);
80.127 + bigger[0] = 0x01;
80.128 + return bigger;
80.129 + }
80.130 + return result;
80.131 + }
80.132 +
80.133 + /**
80.134 * Adds the contents of the int arrays x and y. This method allocates
80.135 * a new int array to hold the answer and returns a reference to that
80.136 * array.
80.137 @@ -1074,14 +1131,17 @@
80.138 int yIndex = y.length;
80.139 int result[] = new int[xIndex];
80.140 long sum = 0;
80.141 -
80.142 - // Add common parts of both numbers
80.143 - while(yIndex > 0) {
80.144 - sum = (x[--xIndex] & LONG_MASK) +
80.145 - (y[--yIndex] & LONG_MASK) + (sum >>> 32);
80.146 + if(yIndex==1) {
80.147 + sum = (x[--xIndex] & LONG_MASK) + (y[0] & LONG_MASK) ;
80.148 result[xIndex] = (int)sum;
80.149 + } else {
80.150 + // Add common parts of both numbers
80.151 + while(yIndex > 0) {
80.152 + sum = (x[--xIndex] & LONG_MASK) +
80.153 + (y[--yIndex] & LONG_MASK) + (sum >>> 32);
80.154 + result[xIndex] = (int)sum;
80.155 + }
80.156 }
80.157 -
80.158 // Copy remainder of longer number while carry propagation is required
80.159 boolean carry = (sum >>> 32 != 0);
80.160 while (xIndex > 0 && carry)
80.161 @@ -1101,6 +1161,71 @@
80.162 return result;
80.163 }
80.164
80.165 + private static int[] subtract(long val, int[] little) {
80.166 + int highWord = (int)(val >>> 32);
80.167 + if (highWord==0) {
80.168 + int result[] = new int[1];
80.169 + result[0] = (int)(val - (little[0] & LONG_MASK));
80.170 + return result;
80.171 + } else {
80.172 + int result[] = new int[2];
80.173 + if(little.length==1) {
80.174 + long difference = ((int)val & LONG_MASK) - (little[0] & LONG_MASK);
80.175 + result[1] = (int)difference;
80.176 + // Subtract remainder of longer number while borrow propagates
80.177 + boolean borrow = (difference >> 32 != 0);
80.178 + if(borrow) {
80.179 + result[0] = highWord - 1;
80.180 + } else { // Copy remainder of longer number
80.181 + result[0] = highWord;
80.182 + }
80.183 + return result;
80.184 + } else { // little.length==2
80.185 + long difference = ((int)val & LONG_MASK) - (little[1] & LONG_MASK);
80.186 + result[1] = (int)difference;
80.187 + difference = (highWord & LONG_MASK) - (little[0] & LONG_MASK) + (difference >> 32);
80.188 + result[0] = (int)difference;
80.189 + return result;
80.190 + }
80.191 + }
80.192 + }
80.193 +
80.194 + /**
80.195 + * Subtracts the contents of the second argument (val) from the
80.196 + * first (big). The first int array (big) must represent a larger number
80.197 + * than the second. This method allocates the space necessary to hold the
80.198 + * answer.
80.199 + * assumes val >= 0
80.200 + */
80.201 + private static int[] subtract(int[] big, long val) {
80.202 + int highWord = (int)(val >>> 32);
80.203 + int bigIndex = big.length;
80.204 + int result[] = new int[bigIndex];
80.205 + long difference = 0;
80.206 +
80.207 + if (highWord==0) {
80.208 + difference = (big[--bigIndex] & LONG_MASK) - val;
80.209 + result[bigIndex] = (int)difference;
80.210 + } else {
80.211 + difference = (big[--bigIndex] & LONG_MASK) - (val & LONG_MASK);
80.212 + result[bigIndex] = (int)difference;
80.213 + difference = (big[--bigIndex] & LONG_MASK) - (highWord & LONG_MASK) + (difference >> 32);
80.214 + result[bigIndex] = (int)difference;
80.215 + }
80.216 +
80.217 +
80.218 + // Subtract remainder of longer number while borrow propagates
80.219 + boolean borrow = (difference >> 32 != 0);
80.220 + while (bigIndex > 0 && borrow)
80.221 + borrow = ((result[--bigIndex] = big[bigIndex] - 1) == -1);
80.222 +
80.223 + // Copy remainder of longer number
80.224 + while (bigIndex > 0)
80.225 + result[--bigIndex] = big[bigIndex];
80.226 +
80.227 + return result;
80.228 + }
80.229 +
80.230 /**
80.231 * Returns a BigInteger whose value is {@code (this - val)}.
80.232 *
80.233 @@ -1165,11 +1290,39 @@
80.234 public BigInteger multiply(BigInteger val) {
80.235 if (val.signum == 0 || signum == 0)
80.236 return ZERO;
80.237 -
80.238 + int resultSign = signum == val.signum ? 1 : -1;
80.239 + if (val.mag.length == 1) {
80.240 + return multiplyByInt(mag,val.mag[0], resultSign);
80.241 + }
80.242 + if(mag.length == 1) {
80.243 + return multiplyByInt(val.mag,mag[0], resultSign);
80.244 + }
80.245 int[] result = multiplyToLen(mag, mag.length,
80.246 val.mag, val.mag.length, null);
80.247 result = trustedStripLeadingZeroInts(result);
80.248 - return new BigInteger(result, signum == val.signum ? 1 : -1);
80.249 + return new BigInteger(result, resultSign);
80.250 + }
80.251 +
80.252 + private static BigInteger multiplyByInt(int[] x, int y, int sign) {
80.253 + if(Integer.bitCount(y)==1) {
80.254 + return new BigInteger(shiftLeft(x,Integer.numberOfTrailingZeros(y)), sign);
80.255 + }
80.256 + int xlen = x.length;
80.257 + int[] rmag = new int[xlen + 1];
80.258 + long carry = 0;
80.259 + long yl = y & LONG_MASK;
80.260 + int rstart = rmag.length - 1;
80.261 + for (int i = xlen - 1; i >= 0; i--) {
80.262 + long product = (x[i] & LONG_MASK) * yl + carry;
80.263 + rmag[rstart--] = (int)product;
80.264 + carry = product >>> 32;
80.265 + }
80.266 + if (carry == 0L) {
80.267 + rmag = java.util.Arrays.copyOfRange(rmag, 1, rmag.length);
80.268 + } else {
80.269 + rmag[rstart] = (int)carry;
80.270 + }
80.271 + return new BigInteger(rmag, sign);
80.272 }
80.273
80.274 /**
80.275 @@ -1339,8 +1492,8 @@
80.276 a = new MutableBigInteger(this.mag),
80.277 b = new MutableBigInteger(val.mag);
80.278
80.279 - a.divide(b, q);
80.280 - return q.toBigInteger(this.signum == val.signum ? 1 : -1);
80.281 + a.divide(b, q, false);
80.282 + return q.toBigInteger(this.signum * val.signum);
80.283 }
80.284
80.285 /**
80.286 @@ -1460,14 +1613,12 @@
80.287 } else { // Array must be resized
80.288 if (nBits <= (32-bitsInHighWord)) {
80.289 int result[] = new int[nInts+len];
80.290 - for (int i=0; i<len; i++)
80.291 - result[i] = a[i];
80.292 + System.arraycopy(a, 0, result, 0, len);
80.293 primitiveLeftShift(result, result.length, nBits);
80.294 return result;
80.295 } else {
80.296 int result[] = new int[nInts+len+1];
80.297 - for (int i=0; i<len; i++)
80.298 - result[i] = a[i];
80.299 + System.arraycopy(a, 0, result, 0, len);
80.300 primitiveRightShift(result, result.length, 32 - nBits);
80.301 return result;
80.302 }
80.303 @@ -1755,9 +1906,7 @@
80.304 b = montReduce(b, mod, modLen, inv);
80.305
80.306 // Set t to high half of b
80.307 - int[] t = new int[modLen];
80.308 - for(int i=0; i<modLen; i++)
80.309 - t[i] = b[i];
80.310 + int[] t = Arrays.copyOf(b, modLen);
80.311
80.312 // Fill in the table with odd powers of the base
80.313 for (int i=1; i<tblmask; i++) {
80.314 @@ -1854,14 +2003,11 @@
80.315
80.316 // Convert result out of Montgomery form and return
80.317 int[] t2 = new int[2*modLen];
80.318 - for(int i=0; i<modLen; i++)
80.319 - t2[i+modLen] = b[i];
80.320 + System.arraycopy(b, 0, t2, modLen, modLen);
80.321
80.322 b = montReduce(t2, mod, modLen, inv);
80.323
80.324 - t2 = new int[modLen];
80.325 - for(int i=0; i<modLen; i++)
80.326 - t2[i] = b[i];
80.327 + t2 = Arrays.copyOf(b, modLen);
80.328
80.329 return new BigInteger(1, t2);
80.330 }
80.331 @@ -2002,8 +2148,7 @@
80.332 // Copy remaining ints of mag
80.333 int numInts = (p + 31) >>> 5;
80.334 int[] mag = new int[numInts];
80.335 - for (int i=0; i<numInts; i++)
80.336 - mag[i] = this.mag[i + (this.mag.length - numInts)];
80.337 + System.arraycopy(this.mag, (this.mag.length - numInts), mag, 0, numInts);
80.338
80.339 // Mask out any excess bits
80.340 int excessBits = (numInts << 5) - p;
80.341 @@ -2069,7 +2214,12 @@
80.342 return shiftRight(-n);
80.343 }
80.344 }
80.345 -
80.346 + int[] newMag = shiftLeft(mag, n);
80.347 +
80.348 + return new BigInteger(newMag, signum);
80.349 + }
80.350 +
80.351 + private static int[] shiftLeft(int[] mag, int n) {
80.352 int nInts = n >>> 5;
80.353 int nBits = n & 0x1f;
80.354 int magLen = mag.length;
80.355 @@ -2077,8 +2227,7 @@
80.356
80.357 if (nBits == 0) {
80.358 newMag = new int[magLen + nInts];
80.359 - for (int i=0; i<magLen; i++)
80.360 - newMag[i] = mag[i];
80.361 + System.arraycopy(mag, 0, newMag, 0, magLen);
80.362 } else {
80.363 int i = 0;
80.364 int nBits2 = 32 - nBits;
80.365 @@ -2094,8 +2243,7 @@
80.366 newMag[i++] = mag[j++] << nBits | mag[j] >>> nBits2;
80.367 newMag[i] = mag[j] << nBits;
80.368 }
80.369 -
80.370 - return new BigInteger(newMag, signum);
80.371 + return newMag;
80.372 }
80.373
80.374 /**
80.375 @@ -2132,9 +2280,7 @@
80.376
80.377 if (nBits == 0) {
80.378 int newMagLen = magLen - nInts;
80.379 - newMag = new int[newMagLen];
80.380 - for (int i=0; i<newMagLen; i++)
80.381 - newMag[i] = mag[i];
80.382 + newMag = Arrays.copyOf(mag, newMagLen);
80.383 } else {
80.384 int i = 0;
80.385 int highBits = mag[0] >>> nBits;
80.386 @@ -2405,7 +2551,7 @@
80.387 if (signum < 0) {
80.388 // Check if magnitude is a power of two
80.389 boolean pow2 = (Integer.bitCount(mag[0]) == 1);
80.390 - for(int i=1; i< len && pow2; i++)
80.391 + for (int i=1; i< len && pow2; i++)
80.392 pow2 = (mag[i] == 0);
80.393
80.394 n = (pow2 ? magBitLength -1 : magBitLength);
80.395 @@ -2530,6 +2676,49 @@
80.396 }
80.397
80.398 /**
80.399 + * Version of compareMagnitude that compares magnitude with long value.
80.400 + * val can't be Long.MIN_VALUE.
80.401 + */
80.402 + final int compareMagnitude(long val) {
80.403 + assert val != Long.MIN_VALUE;
80.404 + int[] m1 = mag;
80.405 + int len = m1.length;
80.406 + if(len > 2) {
80.407 + return 1;
80.408 + }
80.409 + if (val < 0) {
80.410 + val = -val;
80.411 + }
80.412 + int highWord = (int)(val >>> 32);
80.413 + if (highWord==0) {
80.414 + if (len < 1)
80.415 + return -1;
80.416 + if (len > 1)
80.417 + return 1;
80.418 + int a = m1[0];
80.419 + int b = (int)val;
80.420 + if (a != b) {
80.421 + return ((a & LONG_MASK) < (b & LONG_MASK))? -1 : 1;
80.422 + }
80.423 + return 0;
80.424 + } else {
80.425 + if (len < 2)
80.426 + return -1;
80.427 + int a = m1[0];
80.428 + int b = highWord;
80.429 + if (a != b) {
80.430 + return ((a & LONG_MASK) < (b & LONG_MASK))? -1 : 1;
80.431 + }
80.432 + a = m1[1];
80.433 + b = (int)val;
80.434 + if (a != b) {
80.435 + return ((a & LONG_MASK) < (b & LONG_MASK))? -1 : 1;
80.436 + }
80.437 + return 0;
80.438 + }
80.439 + }
80.440 +
80.441 + /**
80.442 * Compares this BigInteger with the specified Object for equality.
80.443 *
80.444 * @param x Object to which this BigInteger is to be compared.
80.445 @@ -3114,25 +3303,35 @@
80.446 }
80.447
80.448 // Commit final fields via Unsafe
80.449 - unsafe.putIntVolatile(this, signumOffset, sign);
80.450 + UnsafeHolder.putSign(this, sign);
80.451
80.452 // Calculate mag field from magnitude and discard magnitude
80.453 - unsafe.putObjectVolatile(this, magOffset,
80.454 - stripLeadingZeroBytes(magnitude));
80.455 + UnsafeHolder.putMag(this, stripLeadingZeroBytes(magnitude));
80.456 }
80.457
80.458 // Support for resetting final fields while deserializing
80.459 - private static final sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
80.460 - private static final long signumOffset;
80.461 - private static final long magOffset;
80.462 - static {
80.463 - try {
80.464 - signumOffset = unsafe.objectFieldOffset
80.465 - (BigInteger.class.getDeclaredField("signum"));
80.466 - magOffset = unsafe.objectFieldOffset
80.467 - (BigInteger.class.getDeclaredField("mag"));
80.468 - } catch (Exception ex) {
80.469 - throw new Error(ex);
80.470 + private static class UnsafeHolder {
80.471 + private static final sun.misc.Unsafe unsafe;
80.472 + private static final long signumOffset;
80.473 + private static final long magOffset;
80.474 + static {
80.475 + try {
80.476 + unsafe = sun.misc.Unsafe.getUnsafe();
80.477 + signumOffset = unsafe.objectFieldOffset
80.478 + (BigInteger.class.getDeclaredField("signum"));
80.479 + magOffset = unsafe.objectFieldOffset
80.480 + (BigInteger.class.getDeclaredField("mag"));
80.481 + } catch (Exception ex) {
80.482 + throw new ExceptionInInitializerError(ex);
80.483 + }
80.484 + }
80.485 +
80.486 + static void putSign(BigInteger bi, int sign) {
80.487 + unsafe.putIntVolatile(bi, signumOffset, sign);
80.488 + }
80.489 +
80.490 + static void putMag(BigInteger bi, int[] magnitude) {
80.491 + unsafe.putObjectVolatile(bi, magOffset, magnitude);
80.492 }
80.493 }
80.494
81.1 --- a/src/share/classes/java/math/MutableBigInteger.java Thu Sep 15 18:53:28 2011 -0700
81.2 +++ b/src/share/classes/java/math/MutableBigInteger.java Mon Sep 19 19:40:59 2011 -0700
81.3 @@ -1,5 +1,5 @@
81.4 /*
81.5 - * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
81.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
81.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81.8 *
81.9 * This code is free software; you can redistribute it and/or modify it
81.10 @@ -160,7 +160,7 @@
81.11 */
81.12 BigDecimal toBigDecimal(int sign, int scale) {
81.13 if (intLen == 0 || sign == 0)
81.14 - return BigDecimal.valueOf(0, scale);
81.15 + return BigDecimal.zeroValueOf(scale);
81.16 int[] mag = getMagnitudeArray();
81.17 int len = mag.length;
81.18 int d = mag[0];
81.19 @@ -171,7 +171,28 @@
81.20 long v = (len == 2) ?
81.21 ((mag[1] & LONG_MASK) | (d & LONG_MASK) << 32) :
81.22 d & LONG_MASK;
81.23 - return new BigDecimal(null, sign == -1 ? -v : v, scale, 0);
81.24 + return BigDecimal.valueOf(sign == -1 ? -v : v, scale);
81.25 + }
81.26 +
81.27 + /**
81.28 + * This is for internal use in converting from a MutableBigInteger
81.29 + * object into a long value given a specified sign.
81.30 + * returns INFLATED if value is not fit into long
81.31 + */
81.32 + long toCompactValue(int sign) {
81.33 + if (intLen == 0 || sign == 0)
81.34 + return 0L;
81.35 + int[] mag = getMagnitudeArray();
81.36 + int len = mag.length;
81.37 + int d = mag[0];
81.38 + // If this MutableBigInteger can not be fitted into long, we need to
81.39 + // make a BigInteger object for the resultant BigDecimal object.
81.40 + if (len > 2 || (d < 0 && len == 2))
81.41 + return INFLATED;
81.42 + long v = (len == 2) ?
81.43 + ((mag[1] & LONG_MASK) | (d & LONG_MASK) << 32) :
81.44 + d & LONG_MASK;
81.45 + return sign == -1 ? -v : v;
81.46 }
81.47
81.48 /**
81.49 @@ -544,6 +565,24 @@
81.50 }
81.51
81.52 /**
81.53 + * The method is the same as mulsun, except the fact that q array is not
81.54 + * updated, the only result of the method is borrow flag.
81.55 + */
81.56 + private int mulsubBorrow(int[] q, int[] a, int x, int len, int offset) {
81.57 + long xLong = x & LONG_MASK;
81.58 + long carry = 0;
81.59 + offset += len;
81.60 + for (int j=len-1; j >= 0; j--) {
81.61 + long product = (a[j] & LONG_MASK) * xLong + carry;
81.62 + long difference = q[offset--] - product;
81.63 + carry = (product >>> 32)
81.64 + + (((difference & LONG_MASK) >
81.65 + (((~(int)product) & LONG_MASK))) ? 1:0);
81.66 + }
81.67 + return (int)carry;
81.68 + }
81.69 +
81.70 + /**
81.71 * Right shift this MutableBigInteger n bits, where n is
81.72 * less than 32.
81.73 * Assumes that intLen > 0, n > 0 for speed
81.74 @@ -842,20 +881,20 @@
81.75 rem = (int) (remLong - (quotient.value[0] * divisorLong));
81.76 remLong = rem & LONG_MASK;
81.77 }
81.78 -
81.79 int xlen = intLen;
81.80 - int[] qWord = new int[2];
81.81 while (--xlen > 0) {
81.82 - long dividendEstimate = (remLong<<32) |
81.83 - (value[offset + intLen - xlen] & LONG_MASK);
81.84 + long dividendEstimate = (remLong << 32) |
81.85 + (value[offset + intLen - xlen] & LONG_MASK);
81.86 + int q;
81.87 if (dividendEstimate >= 0) {
81.88 - qWord[0] = (int) (dividendEstimate / divisorLong);
81.89 - qWord[1] = (int) (dividendEstimate - qWord[0] * divisorLong);
81.90 + q = (int) (dividendEstimate / divisorLong);
81.91 + rem = (int) (dividendEstimate - q * divisorLong);
81.92 } else {
81.93 - divWord(qWord, dividendEstimate, divisor);
81.94 + long tmp = divWord(dividendEstimate, divisor);
81.95 + q = (int) (tmp & LONG_MASK);
81.96 + rem = (int) (tmp >>> 32);
81.97 }
81.98 - quotient.value[intLen - xlen] = qWord[0];
81.99 - rem = qWord[1];
81.100 + quotient.value[intLen - xlen] = q;
81.101 remLong = rem & LONG_MASK;
81.102 }
81.103
81.104 @@ -879,40 +918,45 @@
81.105 *
81.106 */
81.107 MutableBigInteger divide(MutableBigInteger b, MutableBigInteger quotient) {
81.108 + return divide(b,quotient,true);
81.109 + }
81.110 +
81.111 + MutableBigInteger divide(MutableBigInteger b, MutableBigInteger quotient, boolean needReminder) {
81.112 if (b.intLen == 0)
81.113 throw new ArithmeticException("BigInteger divide by zero");
81.114
81.115 // Dividend is zero
81.116 if (intLen == 0) {
81.117 quotient.intLen = quotient.offset;
81.118 - return new MutableBigInteger();
81.119 + return needReminder ? new MutableBigInteger() : null;
81.120 }
81.121
81.122 int cmp = compare(b);
81.123 // Dividend less than divisor
81.124 if (cmp < 0) {
81.125 quotient.intLen = quotient.offset = 0;
81.126 - return new MutableBigInteger(this);
81.127 + return needReminder ? new MutableBigInteger(this) : null;
81.128 }
81.129 // Dividend equal to divisor
81.130 if (cmp == 0) {
81.131 quotient.value[0] = quotient.intLen = 1;
81.132 quotient.offset = 0;
81.133 - return new MutableBigInteger();
81.134 + return needReminder ? new MutableBigInteger() : null;
81.135 }
81.136
81.137 quotient.clear();
81.138 // Special case one word divisor
81.139 if (b.intLen == 1) {
81.140 int r = divideOneWord(b.value[b.offset], quotient);
81.141 - if (r == 0)
81.142 - return new MutableBigInteger();
81.143 - return new MutableBigInteger(r);
81.144 + if(needReminder) {
81.145 + if (r == 0)
81.146 + return new MutableBigInteger();
81.147 + return new MutableBigInteger(r);
81.148 + } else {
81.149 + return null;
81.150 + }
81.151 }
81.152 -
81.153 - // Copy divisor value to protect divisor
81.154 - int[] div = Arrays.copyOfRange(b.value, b.offset, b.offset + b.intLen);
81.155 - return divideMagnitude(div, quotient);
81.156 + return divideMagnitude(b, quotient, needReminder);
81.157 }
81.158
81.159 /**
81.160 @@ -940,30 +984,72 @@
81.161 if (d == 0)
81.162 return divideOneWord((int)v, quotient) & LONG_MASK;
81.163 else {
81.164 - int[] div = new int[]{ d, (int)(v & LONG_MASK) };
81.165 - return divideMagnitude(div, quotient).toLong();
81.166 + return divideLongMagnitude(v, quotient).toLong();
81.167 }
81.168 }
81.169
81.170 + private static void copyAndShift(int[] src, int srcFrom, int srcLen, int[] dst, int dstFrom, int shift) {
81.171 + int n2 = 32 - shift;
81.172 + int c=src[srcFrom];
81.173 + for (int i=0; i < srcLen-1; i++) {
81.174 + int b = c;
81.175 + c = src[++srcFrom];
81.176 + dst[dstFrom+i] = (b << shift) | (c >>> n2);
81.177 + }
81.178 + dst[dstFrom+srcLen-1] = c << shift;
81.179 + }
81.180 +
81.181 /**
81.182 - * Divide this MutableBigInteger by the divisor represented by its magnitude
81.183 - * array. The quotient will be placed into the provided quotient object &
81.184 + * Divide this MutableBigInteger by the divisor.
81.185 + * The quotient will be placed into the provided quotient object &
81.186 * the remainder object is returned.
81.187 */
81.188 - private MutableBigInteger divideMagnitude(int[] divisor,
81.189 - MutableBigInteger quotient) {
81.190 -
81.191 - // Remainder starts as dividend with space for a leading zero
81.192 - MutableBigInteger rem = new MutableBigInteger(new int[intLen + 1]);
81.193 - System.arraycopy(value, offset, rem.value, 1, intLen);
81.194 - rem.intLen = intLen;
81.195 - rem.offset = 1;
81.196 + private MutableBigInteger divideMagnitude(MutableBigInteger div,
81.197 + MutableBigInteger quotient,
81.198 + boolean needReminder ) {
81.199 + // assert div.intLen > 1
81.200 + // D1 normalize the divisor
81.201 + int shift = Integer.numberOfLeadingZeros(div.value[div.offset]);
81.202 + // Copy divisor value to protect divisor
81.203 + final int dlen = div.intLen;
81.204 + int[] divisor;
81.205 + MutableBigInteger rem; // Remainder starts as dividend with space for a leading zero
81.206 + if (shift > 0) {
81.207 + divisor = new int[dlen];
81.208 + copyAndShift(div.value,div.offset,dlen,divisor,0,shift);
81.209 + if(Integer.numberOfLeadingZeros(value[offset])>=shift) {
81.210 + int[] remarr = new int[intLen + 1];
81.211 + rem = new MutableBigInteger(remarr);
81.212 + rem.intLen = intLen;
81.213 + rem.offset = 1;
81.214 + copyAndShift(value,offset,intLen,remarr,1,shift);
81.215 + } else {
81.216 + int[] remarr = new int[intLen + 2];
81.217 + rem = new MutableBigInteger(remarr);
81.218 + rem.intLen = intLen+1;
81.219 + rem.offset = 1;
81.220 + int rFrom = offset;
81.221 + int c=0;
81.222 + int n2 = 32 - shift;
81.223 + for (int i=1; i < intLen+1; i++,rFrom++) {
81.224 + int b = c;
81.225 + c = value[rFrom];
81.226 + remarr[i] = (b << shift) | (c >>> n2);
81.227 + }
81.228 + remarr[intLen+1] = c << shift;
81.229 + }
81.230 + } else {
81.231 + divisor = Arrays.copyOfRange(div.value, div.offset, div.offset + div.intLen);
81.232 + rem = new MutableBigInteger(new int[intLen + 1]);
81.233 + System.arraycopy(value, offset, rem.value, 1, intLen);
81.234 + rem.intLen = intLen;
81.235 + rem.offset = 1;
81.236 + }
81.237
81.238 int nlen = rem.intLen;
81.239
81.240 // Set the quotient size
81.241 - int dlen = divisor.length;
81.242 - int limit = nlen - dlen + 1;
81.243 + final int limit = nlen - dlen + 1;
81.244 if (quotient.value.length < limit) {
81.245 quotient.value = new int[limit];
81.246 quotient.offset = 0;
81.247 @@ -971,14 +1057,6 @@
81.248 quotient.intLen = limit;
81.249 int[] q = quotient.value;
81.250
81.251 - // D1 normalize the divisor
81.252 - int shift = Integer.numberOfLeadingZeros(divisor[0]);
81.253 - if (shift > 0) {
81.254 - // First shift will not grow array
81.255 - BigInteger.primitiveLeftShift(divisor, dlen, shift);
81.256 - // But this one might
81.257 - rem.leftShift(shift);
81.258 - }
81.259
81.260 // Must insert leading 0 in rem if its length did not change
81.261 if (rem.intLen == nlen) {
81.262 @@ -990,10 +1068,9 @@
81.263 int dh = divisor[0];
81.264 long dhLong = dh & LONG_MASK;
81.265 int dl = divisor[1];
81.266 - int[] qWord = new int[2];
81.267
81.268 // D2 Initialize j
81.269 - for(int j=0; j<limit; j++) {
81.270 + for(int j=0; j<limit-1; j++) {
81.271 // D3 Calculate qhat
81.272 // estimate qhat
81.273 int qhat = 0;
81.274 @@ -1013,9 +1090,9 @@
81.275 qhat = (int) (nChunk / dhLong);
81.276 qrem = (int) (nChunk - (qhat * dhLong));
81.277 } else {
81.278 - divWord(qWord, nChunk, dh);
81.279 - qhat = qWord[0];
81.280 - qrem = qWord[1];
81.281 + long tmp = divWord(nChunk, dh);
81.282 + qhat = (int) (tmp & LONG_MASK);
81.283 + qrem = (int) (tmp >>> 32);
81.284 }
81.285 }
81.286
81.287 @@ -1053,6 +1130,181 @@
81.288 // Store the quotient digit
81.289 q[j] = qhat;
81.290 } // D7 loop on j
81.291 + // D3 Calculate qhat
81.292 + // estimate qhat
81.293 + int qhat = 0;
81.294 + int qrem = 0;
81.295 + boolean skipCorrection = false;
81.296 + int nh = rem.value[limit - 1 + rem.offset];
81.297 + int nh2 = nh + 0x80000000;
81.298 + int nm = rem.value[limit + rem.offset];
81.299 +
81.300 + if (nh == dh) {
81.301 + qhat = ~0;
81.302 + qrem = nh + nm;
81.303 + skipCorrection = qrem + 0x80000000 < nh2;
81.304 + } else {
81.305 + long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
81.306 + if (nChunk >= 0) {
81.307 + qhat = (int) (nChunk / dhLong);
81.308 + qrem = (int) (nChunk - (qhat * dhLong));
81.309 + } else {
81.310 + long tmp = divWord(nChunk, dh);
81.311 + qhat = (int) (tmp & LONG_MASK);
81.312 + qrem = (int) (tmp >>> 32);
81.313 + }
81.314 + }
81.315 + if (qhat != 0) {
81.316 + if (!skipCorrection) { // Correct qhat
81.317 + long nl = rem.value[limit + 1 + rem.offset] & LONG_MASK;
81.318 + long rs = ((qrem & LONG_MASK) << 32) | nl;
81.319 + long estProduct = (dl & LONG_MASK) * (qhat & LONG_MASK);
81.320 +
81.321 + if (unsignedLongCompare(estProduct, rs)) {
81.322 + qhat--;
81.323 + qrem = (int) ((qrem & LONG_MASK) + dhLong);
81.324 + if ((qrem & LONG_MASK) >= dhLong) {
81.325 + estProduct -= (dl & LONG_MASK);
81.326 + rs = ((qrem & LONG_MASK) << 32) | nl;
81.327 + if (unsignedLongCompare(estProduct, rs))
81.328 + qhat--;
81.329 + }
81.330 + }
81.331 + }
81.332 +
81.333 +
81.334 + // D4 Multiply and subtract
81.335 + int borrow;
81.336 + rem.value[limit - 1 + rem.offset] = 0;
81.337 + if(needReminder)
81.338 + borrow = mulsub(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset);
81.339 + else
81.340 + borrow = mulsubBorrow(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset);
81.341 +
81.342 + // D5 Test remainder
81.343 + if (borrow + 0x80000000 > nh2) {
81.344 + // D6 Add back
81.345 + if(needReminder)
81.346 + divadd(divisor, rem.value, limit - 1 + 1 + rem.offset);
81.347 + qhat--;
81.348 + }
81.349 +
81.350 + // Store the quotient digit
81.351 + q[(limit - 1)] = qhat;
81.352 + }
81.353 +
81.354 +
81.355 + if(needReminder) {
81.356 + // D8 Unnormalize
81.357 + if (shift > 0)
81.358 + rem.rightShift(shift);
81.359 + rem.normalize();
81.360 + }
81.361 + quotient.normalize();
81.362 + return needReminder ? rem : null;
81.363 + }
81.364 +
81.365 + /**
81.366 + * Divide this MutableBigInteger by the divisor represented by positive long
81.367 + * value. The quotient will be placed into the provided quotient object &
81.368 + * the remainder object is returned.
81.369 + */
81.370 + private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger quotient) {
81.371 + // Remainder starts as dividend with space for a leading zero
81.372 + MutableBigInteger rem = new MutableBigInteger(new int[intLen + 1]);
81.373 + System.arraycopy(value, offset, rem.value, 1, intLen);
81.374 + rem.intLen = intLen;
81.375 + rem.offset = 1;
81.376 +
81.377 + int nlen = rem.intLen;
81.378 +
81.379 + int limit = nlen - 2 + 1;
81.380 + if (quotient.value.length < limit) {
81.381 + quotient.value = new int[limit];
81.382 + quotient.offset = 0;
81.383 + }
81.384 + quotient.intLen = limit;
81.385 + int[] q = quotient.value;
81.386 +
81.387 + // D1 normalize the divisor
81.388 + int shift = Long.numberOfLeadingZeros(ldivisor);
81.389 + if (shift > 0) {
81.390 + ldivisor<<=shift;
81.391 + rem.leftShift(shift);
81.392 + }
81.393 +
81.394 + // Must insert leading 0 in rem if its length did not change
81.395 + if (rem.intLen == nlen) {
81.396 + rem.offset = 0;
81.397 + rem.value[0] = 0;
81.398 + rem.intLen++;
81.399 + }
81.400 +
81.401 + int dh = (int)(ldivisor >>> 32);
81.402 + long dhLong = dh & LONG_MASK;
81.403 + int dl = (int)(ldivisor & LONG_MASK);
81.404 +
81.405 + // D2 Initialize j
81.406 + for (int j = 0; j < limit; j++) {
81.407 + // D3 Calculate qhat
81.408 + // estimate qhat
81.409 + int qhat = 0;
81.410 + int qrem = 0;
81.411 + boolean skipCorrection = false;
81.412 + int nh = rem.value[j + rem.offset];
81.413 + int nh2 = nh + 0x80000000;
81.414 + int nm = rem.value[j + 1 + rem.offset];
81.415 +
81.416 + if (nh == dh) {
81.417 + qhat = ~0;
81.418 + qrem = nh + nm;
81.419 + skipCorrection = qrem + 0x80000000 < nh2;
81.420 + } else {
81.421 + long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
81.422 + if (nChunk >= 0) {
81.423 + qhat = (int) (nChunk / dhLong);
81.424 + qrem = (int) (nChunk - (qhat * dhLong));
81.425 + } else {
81.426 + long tmp = divWord(nChunk, dh);
81.427 + qhat =(int)(tmp & LONG_MASK);
81.428 + qrem = (int)(tmp>>>32);
81.429 + }
81.430 + }
81.431 +
81.432 + if (qhat == 0)
81.433 + continue;
81.434 +
81.435 + if (!skipCorrection) { // Correct qhat
81.436 + long nl = rem.value[j + 2 + rem.offset] & LONG_MASK;
81.437 + long rs = ((qrem & LONG_MASK) << 32) | nl;
81.438 + long estProduct = (dl & LONG_MASK) * (qhat & LONG_MASK);
81.439 +
81.440 + if (unsignedLongCompare(estProduct, rs)) {
81.441 + qhat--;
81.442 + qrem = (int) ((qrem & LONG_MASK) + dhLong);
81.443 + if ((qrem & LONG_MASK) >= dhLong) {
81.444 + estProduct -= (dl & LONG_MASK);
81.445 + rs = ((qrem & LONG_MASK) << 32) | nl;
81.446 + if (unsignedLongCompare(estProduct, rs))
81.447 + qhat--;
81.448 + }
81.449 + }
81.450 + }
81.451 +
81.452 + // D4 Multiply and subtract
81.453 + rem.value[j + rem.offset] = 0;
81.454 + int borrow = mulsubLong(rem.value, dh, dl, qhat, j + rem.offset);
81.455 +
81.456 + // D5 Test remainder
81.457 + if (borrow + 0x80000000 > nh2) {
81.458 + // D6 Add back
81.459 + divaddLong(dh,dl, rem.value, j + 1 + rem.offset);
81.460 + qhat--;
81.461 + }
81.462 +
81.463 + // Store the quotient digit
81.464 + q[j] = qhat;
81.465 + } // D7 loop on j
81.466
81.467 // D8 Unnormalize
81.468 if (shift > 0)
81.469 @@ -1064,6 +1316,46 @@
81.470 }
81.471
81.472 /**
81.473 + * A primitive used for division by long.
81.474 + * Specialized version of the method divadd.
81.475 + * dh is a high part of the divisor, dl is a low part
81.476 + */
81.477 + private int divaddLong(int dh, int dl, int[] result, int offset) {
81.478 + long carry = 0;
81.479 +
81.480 + long sum = (dl & LONG_MASK) + (result[1+offset] & LONG_MASK);
81.481 + result[1+offset] = (int)sum;
81.482 +
81.483 + sum = (dh & LONG_MASK) + (result[offset] & LONG_MASK) + carry;
81.484 + result[offset] = (int)sum;
81.485 + carry = sum >>> 32;
81.486 + return (int)carry;
81.487 + }
81.488 +
81.489 + /**
81.490 + * This method is used for division by long.
81.491 + * Specialized version of the method sulsub.
81.492 + * dh is a high part of the divisor, dl is a low part
81.493 + */
81.494 + private int mulsubLong(int[] q, int dh, int dl, int x, int offset) {
81.495 + long xLong = x & LONG_MASK;
81.496 + offset += 2;
81.497 + long product = (dl & LONG_MASK) * xLong;
81.498 + long difference = q[offset] - product;
81.499 + q[offset--] = (int)difference;
81.500 + long carry = (product >>> 32)
81.501 + + (((difference & LONG_MASK) >
81.502 + (((~(int)product) & LONG_MASK))) ? 1:0);
81.503 + product = (dh & LONG_MASK) * xLong + carry;
81.504 + difference = q[offset] - product;
81.505 + q[offset--] = (int)difference;
81.506 + carry = (product >>> 32)
81.507 + + (((difference & LONG_MASK) >
81.508 + (((~(int)product) & LONG_MASK))) ? 1:0);
81.509 + return (int)carry;
81.510 + }
81.511 +
81.512 + /**
81.513 * Compare two longs as if they were unsigned.
81.514 * Returns true iff one is bigger than two.
81.515 */
81.516 @@ -1075,19 +1367,22 @@
81.517 * This method divides a long quantity by an int to estimate
81.518 * qhat for two multi precision numbers. It is used when
81.519 * the signed value of n is less than zero.
81.520 + * Returns long value where high 32 bits contain reminder value and
81.521 + * low 32 bits contain quotient value.
81.522 */
81.523 - private void divWord(int[] result, long n, int d) {
81.524 + static long divWord(long n, int d) {
81.525 long dLong = d & LONG_MASK;
81.526 -
81.527 + long r;
81.528 + long q;
81.529 if (dLong == 1) {
81.530 - result[0] = (int)n;
81.531 - result[1] = 0;
81.532 - return;
81.533 + q = (int)n;
81.534 + r = 0;
81.535 + return (r << 32) | (q & LONG_MASK);
81.536 }
81.537
81.538 // Approximate the quotient and remainder
81.539 - long q = (n >>> 1) / (dLong >>> 1);
81.540 - long r = n - q*dLong;
81.541 + q = (n >>> 1) / (dLong >>> 1);
81.542 + r = n - q*dLong;
81.543
81.544 // Correct the approximation
81.545 while (r < 0) {
81.546 @@ -1098,10 +1393,8 @@
81.547 r -= dLong;
81.548 q++;
81.549 }
81.550 -
81.551 // n - q*dlong == r && 0 <= r <dLong, hence we're done.
81.552 - result[0] = (int)q;
81.553 - result[1] = (int)r;
81.554 + return (r << 32) | (q & LONG_MASK);
81.555 }
81.556
81.557 /**
81.558 @@ -1473,5 +1766,4 @@
81.559 mod.subtract(t1);
81.560 return mod;
81.561 }
81.562 -
81.563 }
82.1 --- a/src/share/classes/java/net/AbstractPlainSocketImpl.java Thu Sep 15 18:53:28 2011 -0700
82.2 +++ b/src/share/classes/java/net/AbstractPlainSocketImpl.java Mon Sep 19 19:40:59 2011 -0700
82.3 @@ -457,10 +457,10 @@
82.4 }
82.5
82.6 /*
82.7 - * If connection has been reset then return 0 to indicate
82.8 - * there are no buffered bytes.
82.9 + * If connection has been reset or shut down for input, then return 0
82.10 + * to indicate there are no buffered bytes.
82.11 */
82.12 - if (isConnectionReset()) {
82.13 + if (isConnectionReset() || shut_rd) {
82.14 return 0;
82.15 }
82.16
83.1 --- a/src/share/classes/java/net/DatagramSocket.java Thu Sep 15 18:53:28 2011 -0700
83.2 +++ b/src/share/classes/java/net/DatagramSocket.java Mon Sep 19 19:40:59 2011 -0700
83.3 @@ -174,9 +174,7 @@
83.4 * @see SecurityManager#checkListen
83.5 */
83.6 public DatagramSocket() throws SocketException {
83.7 - // create a datagram socket.
83.8 - createImpl();
83.9 - bind(new InetSocketAddress(0));
83.10 + this(new InetSocketAddress(0));
83.11 }
83.12
83.13 /**
83.14 @@ -221,7 +219,12 @@
83.15 // create a datagram socket.
83.16 createImpl();
83.17 if (bindaddr != null) {
83.18 - bind(bindaddr);
83.19 + try {
83.20 + bind(bindaddr);
83.21 + } finally {
83.22 + if (!isBound())
83.23 + close();
83.24 + }
83.25 }
83.26 }
83.27
84.1 --- a/src/share/classes/java/net/MulticastSocket.java Thu Sep 15 18:53:28 2011 -0700
84.2 +++ b/src/share/classes/java/net/MulticastSocket.java Mon Sep 19 19:40:59 2011 -0700
84.3 @@ -162,7 +162,12 @@
84.4 setReuseAddress(true);
84.5
84.6 if (bindaddr != null) {
84.7 - bind(bindaddr);
84.8 + try {
84.9 + bind(bindaddr);
84.10 + } finally {
84.11 + if (!isBound())
84.12 + close();
84.13 + }
84.14 }
84.15 }
84.16
85.1 --- a/src/share/classes/java/net/Socket.java Thu Sep 15 18:53:28 2011 -0700
85.2 +++ b/src/share/classes/java/net/Socket.java Mon Sep 19 19:40:59 2011 -0700
85.3 @@ -28,7 +28,6 @@
85.4 import java.io.InputStream;
85.5 import java.io.OutputStream;
85.6 import java.io.IOException;
85.7 -import java.io.InterruptedIOException;
85.8 import java.nio.channels.SocketChannel;
85.9 import java.security.AccessController;
85.10 import java.security.PrivilegedExceptionAction;
85.11 @@ -421,10 +420,13 @@
85.12 createImpl(stream);
85.13 if (localAddr != null)
85.14 bind(localAddr);
85.15 - if (address != null)
85.16 - connect(address);
85.17 - } catch (IOException e) {
85.18 - close();
85.19 + connect(address);
85.20 + } catch (IOException | IllegalArgumentException | SecurityException e) {
85.21 + try {
85.22 + close();
85.23 + } catch (IOException ce) {
85.24 + e.addSuppressed(ce);
85.25 + }
85.26 throw e;
85.27 }
85.28 }
85.29 @@ -1436,8 +1438,9 @@
85.30 * Any data sent to the input stream side of the socket is acknowledged
85.31 * and then silently discarded.
85.32 * <p>
85.33 - * If you read from a socket input stream after invoking
85.34 - * shutdownInput() on the socket, the stream will return EOF.
85.35 + * If you read from a socket input stream after invoking this method on the
85.36 + * socket, the stream's {@code available} method will return 0, and its
85.37 + * {@code read} methods will return {@code -1} (end of stream).
85.38 *
85.39 * @exception IOException if an I/O error occurs when shutting down this
85.40 * socket.
86.1 --- a/src/share/classes/java/net/SocketImpl.java Thu Sep 15 18:53:28 2011 -0700
86.2 +++ b/src/share/classes/java/net/SocketImpl.java Mon Sep 19 19:40:59 2011 -0700
86.3 @@ -181,8 +181,9 @@
86.4 * Any data sent to this socket is acknowledged and then
86.5 * silently discarded.
86.6 *
86.7 - * If you read from a socket input stream after invoking
86.8 - * shutdownInput() on the socket, the stream will return EOF.
86.9 + * If you read from a socket input stream after invoking this method on the
86.10 + * socket, the stream's {@code available} method will return 0, and its
86.11 + * {@code read} methods will return {@code -1} (end of stream).
86.12 *
86.13 * @exception IOException if an I/O error occurs when shutting down this
86.14 * socket.
87.1 --- a/src/share/classes/java/net/URI.java Thu Sep 15 18:53:28 2011 -0700
87.2 +++ b/src/share/classes/java/net/URI.java Mon Sep 19 19:40:59 2011 -0700
87.3 @@ -1711,6 +1711,8 @@
87.4 i++;
87.5 continue;
87.6 }
87.7 + if (d != '%')
87.8 + return false;
87.9 i++;
87.10 if (toLower(s.charAt(i)) != toLower(t.charAt(i)))
87.11 return false;
88.1 --- a/src/share/classes/java/rmi/dgc/VMID.java Thu Sep 15 18:53:28 2011 -0700
88.2 +++ b/src/share/classes/java/rmi/dgc/VMID.java Mon Sep 19 19:40:59 2011 -0700
88.3 @@ -170,7 +170,7 @@
88.4 /* can't happen, but be deterministic anyway. */
88.5 addrHash = new byte[0];
88.6 } catch (NoSuchAlgorithmException complain) {
88.7 - throw new InternalError(complain.toString());
88.8 + throw new InternalError(complain.toString(), complain);
88.9 }
88.10 return addrHash;
88.11 }
89.1 --- a/src/share/classes/java/security/cert/CollectionCertStoreParameters.java Thu Sep 15 18:53:28 2011 -0700
89.2 +++ b/src/share/classes/java/security/cert/CollectionCertStoreParameters.java Mon Sep 19 19:40:59 2011 -0700
89.3 @@ -122,7 +122,7 @@
89.4 return super.clone();
89.5 } catch (CloneNotSupportedException e) {
89.6 /* Cannot happen */
89.7 - throw new InternalError(e.toString());
89.8 + throw new InternalError(e.toString(), e);
89.9 }
89.10 }
89.11
90.1 --- a/src/share/classes/java/security/cert/LDAPCertStoreParameters.java Thu Sep 15 18:53:28 2011 -0700
90.2 +++ b/src/share/classes/java/security/cert/LDAPCertStoreParameters.java Mon Sep 19 19:40:59 2011 -0700
90.3 @@ -128,7 +128,7 @@
90.4 return super.clone();
90.5 } catch (CloneNotSupportedException e) {
90.6 /* Cannot happen */
90.7 - throw new InternalError(e.toString());
90.8 + throw new InternalError(e.toString(), e);
90.9 }
90.10 }
90.11
91.1 --- a/src/share/classes/java/security/cert/PKIXCertPathChecker.java Thu Sep 15 18:53:28 2011 -0700
91.2 +++ b/src/share/classes/java/security/cert/PKIXCertPathChecker.java Mon Sep 19 19:40:59 2011 -0700
91.3 @@ -175,7 +175,7 @@
91.4 return super.clone();
91.5 } catch (CloneNotSupportedException e) {
91.6 /* Cannot happen */
91.7 - throw new InternalError(e.toString());
91.8 + throw new InternalError(e.toString(), e);
91.9 }
91.10 }
91.11 }
92.1 --- a/src/share/classes/java/security/cert/PKIXCertPathValidatorResult.java Thu Sep 15 18:53:28 2011 -0700
92.2 +++ b/src/share/classes/java/security/cert/PKIXCertPathValidatorResult.java Mon Sep 19 19:40:59 2011 -0700
92.3 @@ -136,7 +136,7 @@
92.4 return super.clone();
92.5 } catch (CloneNotSupportedException e) {
92.6 /* Cannot happen */
92.7 - throw new InternalError(e.toString());
92.8 + throw new InternalError(e.toString(), e);
92.9 }
92.10 }
92.11
93.1 --- a/src/share/classes/java/security/cert/PKIXParameters.java Thu Sep 15 18:53:28 2011 -0700
93.2 +++ b/src/share/classes/java/security/cert/PKIXParameters.java Mon Sep 19 19:40:59 2011 -0700
93.3 @@ -683,7 +683,7 @@
93.4 return copy;
93.5 } catch (CloneNotSupportedException e) {
93.6 /* Cannot happen */
93.7 - throw new InternalError(e.toString());
93.8 + throw new InternalError(e.toString(), e);
93.9 }
93.10 }
93.11
94.1 --- a/src/share/classes/java/security/cert/X509CRLSelector.java Thu Sep 15 18:53:28 2011 -0700
94.2 +++ b/src/share/classes/java/security/cert/X509CRLSelector.java Mon Sep 19 19:40:59 2011 -0700
94.3 @@ -708,7 +708,7 @@
94.4 return copy;
94.5 } catch (CloneNotSupportedException e) {
94.6 /* Cannot happen */
94.7 - throw new InternalError(e.toString());
94.8 + throw new InternalError(e.toString(), e);
94.9 }
94.10 }
94.11 }
95.1 --- a/src/share/classes/java/security/cert/X509CertSelector.java Thu Sep 15 18:53:28 2011 -0700
95.2 +++ b/src/share/classes/java/security/cert/X509CertSelector.java Mon Sep 19 19:40:59 2011 -0700
95.3 @@ -2615,7 +2615,7 @@
95.4 return copy;
95.5 } catch (CloneNotSupportedException e) {
95.6 /* Cannot happen */
95.7 - throw new InternalError(e.toString());
95.8 + throw new InternalError(e.toString(), e);
95.9 }
95.10 }
95.11 }
96.1 --- a/src/share/classes/java/text/AttributedString.java Thu Sep 15 18:53:28 2011 -0700
96.2 +++ b/src/share/classes/java/text/AttributedString.java Mon Sep 19 19:40:59 2011 -0700
96.3 @@ -794,7 +794,7 @@
96.4 return other;
96.5 }
96.6 catch (CloneNotSupportedException e) {
96.7 - throw new InternalError();
96.8 + throw new InternalError(e);
96.9 }
96.10 }
96.11
97.1 --- a/src/share/classes/java/text/BreakDictionary.java Thu Sep 15 18:53:28 2011 -0700
97.2 +++ b/src/share/classes/java/text/BreakDictionary.java Mon Sep 19 19:40:59 2011 -0700
97.3 @@ -154,7 +154,7 @@
97.4 );
97.5 }
97.6 catch (PrivilegedActionException e) {
97.7 - throw new InternalError(e.toString());
97.8 + throw new InternalError(e.toString(), e);
97.9 }
97.10
97.11 byte[] buf = new byte[8];
98.1 --- a/src/share/classes/java/text/BreakIterator.java Thu Sep 15 18:53:28 2011 -0700
98.2 +++ b/src/share/classes/java/text/BreakIterator.java Mon Sep 19 19:40:59 2011 -0700
98.3 @@ -254,7 +254,7 @@
98.4 return super.clone();
98.5 }
98.6 catch (CloneNotSupportedException e) {
98.7 - throw new InternalError();
98.8 + throw new InternalError(e);
98.9 }
98.10 }
98.11
98.12 @@ -617,7 +617,7 @@
98.13 }
98.14 }
98.15 catch (Exception e) {
98.16 - throw new InternalError(e.toString());
98.17 + throw new InternalError(e.toString(), e);
98.18 }
98.19 }
98.20
99.1 --- a/src/share/classes/java/text/Collator.java Thu Sep 15 18:53:28 2011 -0700
99.2 +++ b/src/share/classes/java/text/Collator.java Mon Sep 19 19:40:59 2011 -0700
99.3 @@ -461,7 +461,7 @@
99.4 try {
99.5 return (Collator)super.clone();
99.6 } catch (CloneNotSupportedException e) {
99.7 - throw new InternalError();
99.8 + throw new InternalError(e);
99.9 }
99.10 }
99.11
100.1 --- a/src/share/classes/java/text/DateFormatSymbols.java Thu Sep 15 18:53:28 2011 -0700
100.2 +++ b/src/share/classes/java/text/DateFormatSymbols.java Mon Sep 19 19:40:59 2011 -0700
100.3 @@ -597,7 +597,7 @@
100.4 copyMembers(this, other);
100.5 return other;
100.6 } catch (CloneNotSupportedException e) {
100.7 - throw new InternalError();
100.8 + throw new InternalError(e);
100.9 }
100.10 }
100.11
101.1 --- a/src/share/classes/java/text/DecimalFormat.java Thu Sep 15 18:53:28 2011 -0700
101.2 +++ b/src/share/classes/java/text/DecimalFormat.java Mon Sep 19 19:40:59 2011 -0700
101.3 @@ -1891,14 +1891,10 @@
101.4 * Standard override; no change in semantics.
101.5 */
101.6 public Object clone() {
101.7 - try {
101.8 - DecimalFormat other = (DecimalFormat) super.clone();
101.9 - other.symbols = (DecimalFormatSymbols) symbols.clone();
101.10 - other.digitList = (DigitList) digitList.clone();
101.11 - return other;
101.12 - } catch (Exception e) {
101.13 - throw new InternalError();
101.14 - }
101.15 + DecimalFormat other = (DecimalFormat) super.clone();
101.16 + other.symbols = (DecimalFormatSymbols) symbols.clone();
101.17 + other.digitList = (DigitList) digitList.clone();
101.18 + return other;
101.19 }
101.20
101.21 /**
102.1 --- a/src/share/classes/java/text/DecimalFormatSymbols.java Thu Sep 15 18:53:28 2011 -0700
102.2 +++ b/src/share/classes/java/text/DecimalFormatSymbols.java Mon Sep 19 19:40:59 2011 -0700
102.3 @@ -479,7 +479,7 @@
102.4 return (DecimalFormatSymbols)super.clone();
102.5 // other fields are bit-copied
102.6 } catch (CloneNotSupportedException e) {
102.7 - throw new InternalError();
102.8 + throw new InternalError(e);
102.9 }
102.10 }
102.11
103.1 --- a/src/share/classes/java/text/DigitList.java Thu Sep 15 18:53:28 2011 -0700
103.2 +++ b/src/share/classes/java/text/DigitList.java Mon Sep 19 19:40:59 2011 -0700
103.3 @@ -632,7 +632,7 @@
103.4 other.tempBuffer = null;
103.5 return other;
103.6 } catch (CloneNotSupportedException e) {
103.7 - throw new InternalError();
103.8 + throw new InternalError(e);
103.9 }
103.10 }
103.11
104.1 --- a/src/share/classes/java/text/Format.java Thu Sep 15 18:53:28 2011 -0700
104.2 +++ b/src/share/classes/java/text/Format.java Mon Sep 19 19:40:59 2011 -0700
104.3 @@ -258,7 +258,7 @@
104.4 return super.clone();
104.5 } catch (CloneNotSupportedException e) {
104.6 // will never happen
104.7 - return null;
104.8 + throw new InternalError(e);
104.9 }
104.10 }
104.11
105.1 --- a/src/share/classes/java/text/RuleBasedBreakIterator.java Thu Sep 15 18:53:28 2011 -0700
105.2 +++ b/src/share/classes/java/text/RuleBasedBreakIterator.java Mon Sep 19 19:40:59 2011 -0700
105.3 @@ -453,7 +453,7 @@
105.4 );
105.5 }
105.6 catch (PrivilegedActionException e) {
105.7 - throw new InternalError(e.toString());
105.8 + throw new InternalError(e.toString(), e);
105.9 }
105.10
105.11 int offset = 0;
106.1 --- a/src/share/classes/java/text/StringCharacterIterator.java Thu Sep 15 18:53:28 2011 -0700
106.2 +++ b/src/share/classes/java/text/StringCharacterIterator.java Mon Sep 19 19:40:59 2011 -0700
106.3 @@ -272,7 +272,7 @@
106.4 return other;
106.5 }
106.6 catch (CloneNotSupportedException e) {
106.7 - throw new InternalError();
106.8 + throw new InternalError(e);
106.9 }
106.10 }
106.11
107.1 --- a/src/share/classes/java/util/ArrayList.java Thu Sep 15 18:53:28 2011 -0700
107.2 +++ b/src/share/classes/java/util/ArrayList.java Mon Sep 19 19:40:59 2011 -0700
107.3 @@ -307,7 +307,7 @@
107.4 return v;
107.5 } catch (CloneNotSupportedException e) {
107.6 // this shouldn't happen, since we are Cloneable
107.7 - throw new InternalError();
107.8 + throw new InternalError(e);
107.9 }
107.10 }
107.11
108.1 --- a/src/share/classes/java/util/BitSet.java Thu Sep 15 18:53:28 2011 -0700
108.2 +++ b/src/share/classes/java/util/BitSet.java Mon Sep 19 19:40:59 2011 -0700
108.3 @@ -1092,7 +1092,7 @@
108.4 result.checkInvariants();
108.5 return result;
108.6 } catch (CloneNotSupportedException e) {
108.7 - throw new InternalError();
108.8 + throw new InternalError(e);
108.9 }
108.10 }
108.11
109.1 --- a/src/share/classes/java/util/Calendar.java Thu Sep 15 18:53:28 2011 -0700
109.2 +++ b/src/share/classes/java/util/Calendar.java Mon Sep 19 19:40:59 2011 -0700
109.3 @@ -2512,7 +2512,7 @@
109.4 }
109.5 catch (CloneNotSupportedException e) {
109.6 // this shouldn't happen, since we are Cloneable
109.7 - throw new InternalError();
109.8 + throw new InternalError(e);
109.9 }
109.10 }
109.11
110.1 --- a/src/share/classes/java/util/Currency.java Thu Sep 15 18:53:28 2011 -0700
110.2 +++ b/src/share/classes/java/util/Currency.java Mon Sep 19 19:40:59 2011 -0700
110.3 @@ -221,9 +221,7 @@
110.4 otherCurrenciesNumericCode = readIntArray(dis, ocCount);
110.5 dis.close();
110.6 } catch (IOException e) {
110.7 - InternalError ie = new InternalError();
110.8 - ie.initCause(e);
110.9 - throw ie;
110.10 + throw new InternalError(e);
110.11 }
110.12
110.13 // look for the properties file for overrides
111.1 --- a/src/share/classes/java/util/HashSet.java Thu Sep 15 18:53:28 2011 -0700
111.2 +++ b/src/share/classes/java/util/HashSet.java Mon Sep 19 19:40:59 2011 -0700
111.3 @@ -253,7 +253,7 @@
111.4 newSet.map = (HashMap<E, Object>) map.clone();
111.5 return newSet;
111.6 } catch (CloneNotSupportedException e) {
111.7 - throw new InternalError();
111.8 + throw new InternalError(e);
111.9 }
111.10 }
111.11
112.1 --- a/src/share/classes/java/util/Hashtable.java Thu Sep 15 18:53:28 2011 -0700
112.2 +++ b/src/share/classes/java/util/Hashtable.java Mon Sep 19 19:40:59 2011 -0700
112.3 @@ -537,7 +537,7 @@
112.4 return t;
112.5 } catch (CloneNotSupportedException e) {
112.6 // this shouldn't happen, since we are Cloneable
112.7 - throw new InternalError();
112.8 + throw new InternalError(e);
112.9 }
112.10 }
112.11
113.1 --- a/src/share/classes/java/util/IdentityHashMap.java Thu Sep 15 18:53:28 2011 -0700
113.2 +++ b/src/share/classes/java/util/IdentityHashMap.java Mon Sep 19 19:40:59 2011 -0700
113.3 @@ -703,7 +703,7 @@
113.4 m.table = table.clone();
113.5 return m;
113.6 } catch (CloneNotSupportedException e) {
113.7 - throw new InternalError();
113.8 + throw new InternalError(e);
113.9 }
113.10 }
113.11
114.1 --- a/src/share/classes/java/util/LinkedList.java Thu Sep 15 18:53:28 2011 -0700
114.2 +++ b/src/share/classes/java/util/LinkedList.java Mon Sep 19 19:40:59 2011 -0700
114.3 @@ -994,7 +994,7 @@
114.4 try {
114.5 return (LinkedList<E>) super.clone();
114.6 } catch (CloneNotSupportedException e) {
114.7 - throw new InternalError();
114.8 + throw new InternalError(e);
114.9 }
114.10 }
114.11
115.1 --- a/src/share/classes/java/util/Locale.java Thu Sep 15 18:53:28 2011 -0700
115.2 +++ b/src/share/classes/java/util/Locale.java Mon Sep 19 19:40:59 2011 -0700
115.3 @@ -1859,7 +1859,7 @@
115.4 Locale that = (Locale)super.clone();
115.5 return that;
115.6 } catch (CloneNotSupportedException e) {
115.7 - throw new InternalError();
115.8 + throw new InternalError(e);
115.9 }
115.10 }
115.11
116.1 --- a/src/share/classes/java/util/ResourceBundle.java Thu Sep 15 18:53:28 2011 -0700
116.2 +++ b/src/share/classes/java/util/ResourceBundle.java Mon Sep 19 19:40:59 2011 -0700
116.3 @@ -614,7 +614,7 @@
116.4 return clone;
116.5 } catch (CloneNotSupportedException e) {
116.6 //this should never happen
116.7 - throw new InternalError();
116.8 + throw new InternalError(e);
116.9 }
116.10 }
116.11
117.1 --- a/src/share/classes/java/util/TimeZone.java Thu Sep 15 18:53:28 2011 -0700
117.2 +++ b/src/share/classes/java/util/TimeZone.java Mon Sep 19 19:40:59 2011 -0700
117.3 @@ -739,7 +739,7 @@
117.4 other.ID = ID;
117.5 return other;
117.6 } catch (CloneNotSupportedException e) {
117.7 - throw new InternalError();
117.8 + throw new InternalError(e);
117.9 }
117.10 }
117.11
118.1 --- a/src/share/classes/java/util/TreeMap.java Thu Sep 15 18:53:28 2011 -0700
118.2 +++ b/src/share/classes/java/util/TreeMap.java Mon Sep 19 19:40:59 2011 -0700
118.3 @@ -622,7 +622,7 @@
118.4 try {
118.5 clone = (TreeMap<K,V>) super.clone();
118.6 } catch (CloneNotSupportedException e) {
118.7 - throw new InternalError();
118.8 + throw new InternalError(e);
118.9 }
118.10
118.11 // Put clone into "virgin" state (except for comparator)
119.1 --- a/src/share/classes/java/util/TreeSet.java Thu Sep 15 18:53:28 2011 -0700
119.2 +++ b/src/share/classes/java/util/TreeSet.java Mon Sep 19 19:40:59 2011 -0700
119.3 @@ -474,7 +474,7 @@
119.4 try {
119.5 clone = (TreeSet<E>) super.clone();
119.6 } catch (CloneNotSupportedException e) {
119.7 - throw new InternalError();
119.8 + throw new InternalError(e);
119.9 }
119.10
119.11 clone.m = new TreeMap<>(m);
120.1 --- a/src/share/classes/java/util/UUID.java Thu Sep 15 18:53:28 2011 -0700
120.2 +++ b/src/share/classes/java/util/UUID.java Mon Sep 19 19:40:59 2011 -0700
120.3 @@ -165,7 +165,7 @@
120.4 try {
120.5 md = MessageDigest.getInstance("MD5");
120.6 } catch (NoSuchAlgorithmException nsae) {
120.7 - throw new InternalError("MD5 not supported");
120.8 + throw new InternalError("MD5 not supported", nsae);
120.9 }
120.10 byte[] md5Bytes = md.digest(name);
120.11 md5Bytes[6] &= 0x0f; /* clear version */
121.1 --- a/src/share/classes/java/util/Vector.java Thu Sep 15 18:53:28 2011 -0700
121.2 +++ b/src/share/classes/java/util/Vector.java Mon Sep 19 19:40:59 2011 -0700
121.3 @@ -673,7 +673,7 @@
121.4 return v;
121.5 } catch (CloneNotSupportedException e) {
121.6 // this shouldn't happen, since we are Cloneable
121.7 - throw new InternalError();
121.8 + throw new InternalError(e);
121.9 }
121.10 }
121.11
122.1 --- a/src/share/classes/java/util/zip/ZipEntry.java Thu Sep 15 18:53:28 2011 -0700
122.2 +++ b/src/share/classes/java/util/zip/ZipEntry.java Mon Sep 19 19:40:59 2011 -0700
122.3 @@ -321,7 +321,7 @@
122.4 return e;
122.5 } catch (CloneNotSupportedException e) {
122.6 // This should never happen, since we are Cloneable
122.7 - throw new InternalError();
122.8 + throw new InternalError(e);
122.9 }
122.10 }
122.11 }
123.1 --- a/src/share/classes/javax/management/openmbean/TabularDataSupport.java Thu Sep 15 18:53:28 2011 -0700
123.2 +++ b/src/share/classes/javax/management/openmbean/TabularDataSupport.java Mon Sep 19 19:40:59 2011 -0700
123.3 @@ -671,7 +671,7 @@
123.4 return c;
123.5 }
123.6 catch (CloneNotSupportedException e) {
123.7 - throw new InternalError(e.toString());
123.8 + throw new InternalError(e.toString(), e);
123.9 }
123.10 }
123.11
124.1 --- a/src/share/classes/javax/swing/AbstractButton.java Thu Sep 15 18:53:28 2011 -0700
124.2 +++ b/src/share/classes/javax/swing/AbstractButton.java Mon Sep 19 19:40:59 2011 -0700
124.3 @@ -981,6 +981,7 @@
124.4 * @param exception the message to use in the
124.5 * {@code IllegalArgumentException} that is thrown for an invalid
124.6 * value
124.7 + * @return the {@code key} argument
124.8 * @exception IllegalArgumentException if key is not one of the legal
124.9 * values listed above
124.10 * @see #setHorizontalTextPosition
124.11 @@ -1011,6 +1012,7 @@
124.12 * @param exception the message to use in the
124.13 * {@code IllegalArgumentException} that is thrown for an invalid
124.14 * value
124.15 + * @return the {@code key} argument
124.16 * @exception IllegalArgumentException if key is not one of the legal
124.17 * values listed above
124.18 */
125.1 --- a/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java Thu Sep 15 18:53:28 2011 -0700
125.2 +++ b/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java Mon Sep 19 19:40:59 2011 -0700
125.3 @@ -1153,10 +1153,15 @@
125.4 if (shellFolder.isLink()) {
125.5 File linkedTo = shellFolder.getLinkLocation();
125.6
125.7 - if (linkedTo != null && fc.isTraversable(linkedTo)) {
125.8 - dir = linkedTo;
125.9 + // If linkedTo is null we try to use dir
125.10 + if (linkedTo != null) {
125.11 + if (fc.isTraversable(linkedTo)) {
125.12 + dir = linkedTo;
125.13 + } else {
125.14 + return;
125.15 + }
125.16 } else {
125.17 - return;
125.18 + dir = shellFolder;
125.19 }
125.20 }
125.21 } catch (FileNotFoundException ex) {
126.1 --- a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java Thu Sep 15 18:53:28 2011 -0700
126.2 +++ b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java Mon Sep 19 19:40:59 2011 -0700
126.3 @@ -461,16 +461,16 @@
126.4
126.5 Locale l = fc.getLocale();
126.6
126.7 - lookInLabelMnemonic = UIManager.getInt("FileChooser.lookInLabelMnemonic");
126.8 + lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
126.9 lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
126.10 saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
126.11
126.12 - fileNameLabelMnemonic = UIManager.getInt("FileChooser.fileNameLabelMnemonic");
126.13 + fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
126.14 fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
126.15 - folderNameLabelMnemonic = UIManager.getInt("FileChooser.folderNameLabelMnemonic");
126.16 + folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
126.17 folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l);
126.18
126.19 - filesOfTypeLabelMnemonic = UIManager.getInt("FileChooser.filesOfTypeLabelMnemonic");
126.20 + filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
126.21 filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
126.22
126.23 upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l);
126.24 @@ -489,6 +489,10 @@
126.25 detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName",l);
126.26 }
126.27
126.28 + private Integer getMnemonic(String key, Locale l) {
126.29 + return SwingUtilities2.getUIDefaultsInt(key, l);
126.30 + }
126.31 +
126.32 protected void installListeners(JFileChooser fc) {
126.33 super.installListeners(fc);
126.34 ActionMap actionMap = getActionMap();
127.1 --- a/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java Thu Sep 15 18:53:28 2011 -0700
127.2 +++ b/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java Mon Sep 19 19:40:59 2011 -0700
127.3 @@ -844,9 +844,6 @@
127.4 "FileChooser.newFolderIcon", new SwingLazyValue("javax.swing.plaf.metal.MetalIconFactory", "getFileChooserNewFolderIcon"),
127.5 "FileChooser.upFolderIcon", new SwingLazyValue("javax.swing.plaf.metal.MetalIconFactory", "getFileChooserUpFolderIcon"),
127.6
127.7 - "FileChooser.lookInLabelMnemonic", new Integer(KeyEvent.VK_I),
127.8 - "FileChooser.fileNameLabelMnemonic", new Integer(KeyEvent.VK_N),
127.9 - "FileChooser.filesOfTypeLabelMnemonic", new Integer(KeyEvent.VK_T),
127.10 "FileChooser.usesSingleFilePane", Boolean.TRUE,
127.11 "FileChooser.ancestorInputMap",
127.12 new UIDefaults.LazyInputMap(new Object[] {
128.1 --- a/src/share/classes/javax/swing/text/ElementIterator.java Thu Sep 15 18:53:28 2011 -0700
128.2 +++ b/src/share/classes/javax/swing/text/ElementIterator.java Mon Sep 19 19:40:59 2011 -0700
128.3 @@ -157,7 +157,7 @@
128.4 }
128.5 return it;
128.6 } catch (CloneNotSupportedException e) {
128.7 - throw new InternalError();
128.8 + throw new InternalError(e);
128.9 }
128.10 }
128.11
129.1 --- a/src/share/classes/javax/swing/text/rtf/RTFReader.java Thu Sep 15 18:53:28 2011 -0700
129.2 +++ b/src/share/classes/javax/swing/text/rtf/RTFReader.java Mon Sep 19 19:40:59 2011 -0700
129.3 @@ -528,7 +528,7 @@
129.4 try {
129.5 translationTable = (char[])getCharacterSet("ansi");
129.6 } catch (IOException e) {
129.7 - throw new InternalError("RTFReader: Unable to find character set resources (" + e + ")");
129.8 + throw new InternalError("RTFReader: Unable to find character set resources (" + e + ")", e);
129.9 }
129.10 }
129.11 }
129.12 @@ -1614,7 +1614,7 @@
129.13 } catch (BadLocationException ble) {
129.14 /* This shouldn't be able to happen, of course */
129.15 /* TODO is InternalError the correct error to throw? */
129.16 - throw new InternalError(ble.getMessage());
129.17 + throw new InternalError(ble.getMessage(), ble);
129.18 }
129.19 }
129.20
129.21 @@ -1628,7 +1628,7 @@
129.22 } catch (BadLocationException ble) {
129.23 /* This shouldn't be able to happen, of course */
129.24 /* TODO is InternalError the correct error to throw? */
129.25 - throw new InternalError(ble.getMessage());
129.26 + throw new InternalError(ble.getMessage(), ble);
129.27 }
129.28 }
129.29
130.1 --- a/src/share/classes/sun/awt/FontConfiguration.java Thu Sep 15 18:53:28 2011 -0700
130.2 +++ b/src/share/classes/sun/awt/FontConfiguration.java Mon Sep 19 19:40:59 2011 -0700
130.3 @@ -1,5 +1,5 @@
130.4 /*
130.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
130.6 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
130.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
130.8 *
130.9 * This code is free software; you can redistribute it and/or modify it
130.10 @@ -266,11 +266,20 @@
130.11 private File findFontConfigFile(String javaLib) {
130.12 String baseName = javaLib + File.separator + "fontconfig";
130.13 File configFile;
130.14 + String osMajorVersion = null;
130.15 if (osVersion != null && osName != null) {
130.16 configFile = findImpl(baseName + "." + osName + "." + osVersion);
130.17 if (configFile != null) {
130.18 return configFile;
130.19 }
130.20 + int decimalPointIndex = osVersion.indexOf(".");
130.21 + if (decimalPointIndex != -1) {
130.22 + osMajorVersion = osVersion.substring(0, osVersion.indexOf("."));
130.23 + configFile = findImpl(baseName + "." + osName + "." + osMajorVersion);
130.24 + if (configFile != null) {
130.25 + return configFile;
130.26 + }
130.27 + }
130.28 }
130.29 if (osName != null) {
130.30 configFile = findImpl(baseName + "." + osName);
130.31 @@ -283,6 +292,12 @@
130.32 if (configFile != null) {
130.33 return configFile;
130.34 }
130.35 + if (osMajorVersion != null) {
130.36 + configFile = findImpl(baseName + "." + osMajorVersion);
130.37 + if (configFile != null) {
130.38 + return configFile;
130.39 + }
130.40 + }
130.41 }
130.42 foundOsSpecificFile = false;
130.43
131.1 --- a/src/share/classes/sun/dc/DuctusRenderingEngine.java Thu Sep 15 18:53:28 2011 -0700
131.2 +++ b/src/share/classes/sun/dc/DuctusRenderingEngine.java Mon Sep 19 19:40:59 2011 -0700
131.3 @@ -158,7 +158,7 @@
131.4 feedConsumer(pi, consumer, normalize, 0.25f);
131.5 } catch (PathException e) {
131.6 throw new InternalError("Unable to Stroke shape ("+
131.7 - e.getMessage()+")");
131.8 + e.getMessage()+")", e);
131.9 } finally {
131.10 while (consumer != null && consumer != sr) {
131.11 PathConsumer next = consumer.getConsumer();
131.12 @@ -763,7 +763,7 @@
131.13 consumer.endPath();
131.14 } catch (PathException e) {
131.15 throw new InternalError("Unable to Stroke shape ("+
131.16 - e.getMessage()+")");
131.17 + e.getMessage()+")", e);
131.18 }
131.19 }
131.20
132.1 --- a/src/share/classes/sun/font/FontLineMetrics.java Thu Sep 15 18:53:28 2011 -0700
132.2 +++ b/src/share/classes/sun/font/FontLineMetrics.java Mon Sep 19 19:40:59 2011 -0700
132.3 @@ -113,7 +113,7 @@
132.4 return super.clone();
132.5 }
132.6 catch (CloneNotSupportedException e) {
132.7 - throw new InternalError();
132.8 + throw new InternalError(e);
132.9 }
132.10 }
132.11 }
133.1 --- a/src/share/classes/sun/font/GlyphLayout.java Thu Sep 15 18:53:28 2011 -0700
133.2 +++ b/src/share/classes/sun/font/GlyphLayout.java Mon Sep 19 19:40:59 2011 -0700
133.3 @@ -233,7 +233,7 @@
133.4 invdtx = dtx.createInverse();
133.5 }
133.6 catch (NoninvertibleTransformException e) {
133.7 - throw new InternalError();
133.8 + throw new InternalError(e);
133.9 }
133.10 }
133.11
134.1 --- a/src/share/classes/sun/invoke/util/ValueConversions.java Thu Sep 15 18:53:28 2011 -0700
134.2 +++ b/src/share/classes/sun/invoke/util/ValueConversions.java Mon Sep 19 19:40:59 2011 -0700
134.3 @@ -677,9 +677,7 @@
134.4 EMPTY = IMPL_LOOKUP.findStatic(THIS_CLASS, "empty", ignoreType.dropParameterTypes(0, 1));
134.5 NEW_ARRAY = IMPL_LOOKUP.findStatic(THIS_CLASS, "newArray", MethodType.methodType(Object[].class, int.class));
134.6 } catch (NoSuchMethodException | IllegalAccessException ex) {
134.7 - Error err = new InternalError("uncaught exception");
134.8 - err.initCause(ex);
134.9 - throw err;
134.10 + throw new InternalError("uncaught exception", ex);
134.11 }
134.12 }
134.13
134.14 @@ -693,9 +691,7 @@
134.15 COPY_AS_PRIMITIVE_ARRAY = IMPL_LOOKUP.findStatic(THIS_CLASS, "copyAsPrimitiveArray", MethodType.methodType(Object.class, Wrapper.class, Object[].class));
134.16 MAKE_LIST = IMPL_LOOKUP.findStatic(THIS_CLASS, "makeList", MethodType.methodType(List.class, Object[].class));
134.17 } catch (ReflectiveOperationException ex) {
134.18 - Error err = new InternalError("uncaught exception");
134.19 - err.initCause(ex);
134.20 - throw err;
134.21 + throw new InternalError("uncaught exception", ex);
134.22 }
134.23 }
134.24 }
135.1 --- a/src/share/classes/sun/java2d/pipe/LoopPipe.java Thu Sep 15 18:53:28 2011 -0700
135.2 +++ b/src/share/classes/sun/java2d/pipe/LoopPipe.java Mon Sep 19 19:40:59 2011 -0700
135.3 @@ -281,9 +281,8 @@
135.4 } catch (Throwable t) {
135.5 sr.dispose();
135.6 sr = null;
135.7 - t.printStackTrace();
135.8 throw new InternalError("Unable to Stroke shape ("+
135.9 - t.getMessage()+")");
135.10 + t.getMessage()+")", t);
135.11 }
135.12 return sr;
135.13 }
136.1 --- a/src/share/classes/sun/management/counter/perf/PerfDataEntry.java Thu Sep 15 18:53:28 2011 -0700
136.2 +++ b/src/share/classes/sun/management/counter/perf/PerfDataEntry.java Mon Sep 19 19:40:59 2011 -0700
136.3 @@ -133,7 +133,7 @@
136.4 catch (UnsupportedEncodingException e) {
136.5 // should not reach here
136.6 // "UTF-8" is always a known encoding
136.7 - throw new InternalError(e.getMessage());
136.8 + throw new InternalError(e.getMessage(), e);
136.9 }
136.10
136.11 if (variability == Variability.INVALID) {
137.1 --- a/src/share/classes/sun/management/counter/perf/PerfDataType.java Thu Sep 15 18:53:28 2011 -0700
137.2 +++ b/src/share/classes/sun/management/counter/perf/PerfDataType.java Mon Sep 19 19:40:59 2011 -0700
137.3 @@ -93,7 +93,7 @@
137.4 this.value = b[0];
137.5 } catch (UnsupportedEncodingException e) {
137.6 // ignore, "UTF-8" is always a known encoding
137.7 - throw new InternalError("Unknown encoding");
137.8 + throw new InternalError("Unknown encoding", e);
137.9 }
137.10 }
137.11 }
138.1 --- a/src/share/classes/sun/misc/Launcher.java Thu Sep 15 18:53:28 2011 -0700
138.2 +++ b/src/share/classes/sun/misc/Launcher.java Mon Sep 19 19:40:59 2011 -0700
138.3 @@ -71,7 +71,7 @@
138.4 extcl = ExtClassLoader.getExtClassLoader();
138.5 } catch (IOException e) {
138.6 throw new InternalError(
138.7 - "Could not create extension class loader");
138.8 + "Could not create extension class loader", e);
138.9 }
138.10
138.11 // Now create the class loader to use to launch the application
138.12 @@ -79,7 +79,7 @@
138.13 loader = AppClassLoader.getAppClassLoader(extcl);
138.14 } catch (IOException e) {
138.15 throw new InternalError(
138.16 - "Could not create application class loader");
138.17 + "Could not create application class loader", e);
138.18 }
138.19
138.20 // Also set the context class loader for the primordial thread.
138.21 @@ -460,7 +460,7 @@
138.22 return ParseUtil.fileToEncodedURL(file);
138.23 } catch (MalformedURLException e) {
138.24 // Should never happen since we specify the protocol...
138.25 - throw new InternalError();
138.26 + throw new InternalError(e);
138.27 }
138.28 }
138.29
138.30 @@ -475,15 +475,10 @@
138.31 try {
138.32 Class c = Class.forName(name);
138.33 return (URLStreamHandler)c.newInstance();
138.34 - } catch (ClassNotFoundException e) {
138.35 - e.printStackTrace();
138.36 - } catch (InstantiationException e) {
138.37 - e.printStackTrace();
138.38 - } catch (IllegalAccessException e) {
138.39 - e.printStackTrace();
138.40 + } catch (ReflectiveOperationException e) {
138.41 + throw new InternalError("could not load " + protocol +
138.42 + "system protocol handler", e);
138.43 }
138.44 - throw new InternalError("could not load " + protocol +
138.45 - "system protocol handler");
138.46 }
138.47 }
138.48 }
139.1 --- a/src/share/classes/sun/misc/ProxyGenerator.java Thu Sep 15 18:53:28 2011 -0700
139.2 +++ b/src/share/classes/sun/misc/ProxyGenerator.java Mon Sep 19 19:40:59 2011 -0700
139.3 @@ -460,7 +460,7 @@
139.4 methods.add(generateStaticInitializer());
139.5
139.6 } catch (IOException e) {
139.7 - throw new InternalError("unexpected I/O Exception");
139.8 + throw new InternalError("unexpected I/O Exception", e);
139.9 }
139.10
139.11 if (methods.size() > 65535) {
139.12 @@ -540,7 +540,7 @@
139.13 dout.writeShort(0); // (no ClassFile attributes for proxy classes)
139.14
139.15 } catch (IOException e) {
139.16 - throw new InternalError("unexpected I/O Exception");
139.17 + throw new InternalError("unexpected I/O Exception", e);
139.18 }
139.19
139.20 return bout.toByteArray();
140.1 --- a/src/share/classes/sun/net/NetworkClient.java Thu Sep 15 18:53:28 2011 -0700
140.2 +++ b/src/share/classes/sun/net/NetworkClient.java Mon Sep 19 19:40:59 2011 -0700
140.3 @@ -139,7 +139,7 @@
140.4 serverSocket.getOutputStream()),
140.5 true, encoding);
140.6 } catch (UnsupportedEncodingException e) {
140.7 - throw new InternalError(encoding +"encoding not found");
140.8 + throw new InternalError(encoding +"encoding not found", e);
140.9 }
140.10 serverInput = new BufferedInputStream(serverSocket.getInputStream());
140.11 }
141.1 --- a/src/share/classes/sun/net/NetworkServer.java Thu Sep 15 18:53:28 2011 -0700
141.2 +++ b/src/share/classes/sun/net/NetworkServer.java Mon Sep 19 19:40:59 2011 -0700
141.3 @@ -142,7 +142,7 @@
141.4 return super.clone();
141.5 } catch (CloneNotSupportedException e) {
141.6 // this shouldn't happen, since we are Cloneable
141.7 - throw new InternalError();
141.8 + throw new InternalError(e);
141.9 }
141.10 }
141.11
142.1 --- a/src/share/classes/sun/net/ftp/impl/FtpClient.java Thu Sep 15 18:53:28 2011 -0700
142.2 +++ b/src/share/classes/sun/net/ftp/impl/FtpClient.java Mon Sep 19 19:40:59 2011 -0700
142.3 @@ -905,7 +905,7 @@
142.4 out = new PrintStream(new BufferedOutputStream(server.getOutputStream()),
142.5 true, encoding);
142.6 } catch (UnsupportedEncodingException e) {
142.7 - throw new InternalError(encoding + "encoding not found");
142.8 + throw new InternalError(encoding + "encoding not found", e);
142.9 }
142.10 in = new BufferedInputStream(server.getInputStream());
142.11 }
142.12 @@ -1621,7 +1621,7 @@
142.13 out = new PrintStream(new BufferedOutputStream(server.getOutputStream()),
142.14 true, encoding);
142.15 } catch (UnsupportedEncodingException e) {
142.16 - throw new InternalError(encoding + "encoding not found");
142.17 + throw new InternalError(encoding + "encoding not found", e);
142.18 }
142.19 in = new BufferedInputStream(server.getInputStream());
142.20 }
142.21 @@ -2056,7 +2056,7 @@
142.22 out = new PrintStream(new BufferedOutputStream(server.getOutputStream()),
142.23 true, encoding);
142.24 } catch (UnsupportedEncodingException e) {
142.25 - throw new InternalError(encoding + "encoding not found");
142.26 + throw new InternalError(encoding + "encoding not found", e);
142.27 }
142.28 in = new BufferedInputStream(server.getInputStream());
142.29
142.30 @@ -2090,7 +2090,7 @@
142.31 out = new PrintStream(new BufferedOutputStream(server.getOutputStream()),
142.32 true, encoding);
142.33 } catch (UnsupportedEncodingException e) {
142.34 - throw new InternalError(encoding + "encoding not found");
142.35 + throw new InternalError(encoding + "encoding not found", e);
142.36 }
142.37 in = new BufferedInputStream(server.getInputStream());
142.38
143.1 --- a/src/share/classes/sun/net/smtp/SmtpClient.java Thu Sep 15 18:53:28 2011 -0700
143.2 +++ b/src/share/classes/sun/net/smtp/SmtpClient.java Mon Sep 19 19:40:59 2011 -0700
143.3 @@ -134,7 +134,7 @@
143.4 try {
143.5 message = new SmtpPrintStream(serverOutput, this);
143.6 } catch (UnsupportedEncodingException e) {
143.7 - throw new InternalError(encoding+" encoding not found");
143.8 + throw new InternalError(encoding+" encoding not found", e);
143.9 }
143.10 return message;
143.11 }
144.1 --- a/src/share/classes/sun/net/www/http/ChunkedOutputStream.java Thu Sep 15 18:53:28 2011 -0700
144.2 +++ b/src/share/classes/sun/net/www/http/ChunkedOutputStream.java Mon Sep 19 19:40:59 2011 -0700
144.3 @@ -79,7 +79,7 @@
144.4 return header;
144.5 } catch (java.io.UnsupportedEncodingException e) {
144.6 /* This should never happen */
144.7 - throw new InternalError(e.getMessage());
144.8 + throw new InternalError(e.getMessage(), e);
144.9 }
144.10 }
144.11
145.1 --- a/src/share/classes/sun/net/www/http/HttpClient.java Thu Sep 15 18:53:28 2011 -0700
145.2 +++ b/src/share/classes/sun/net/www/http/HttpClient.java Mon Sep 19 19:40:59 2011 -0700
145.3 @@ -395,7 +395,7 @@
145.4 new BufferedOutputStream(out),
145.5 false, encoding);
145.6 } catch (UnsupportedEncodingException e) {
145.7 - throw new InternalError(encoding+" encoding not found");
145.8 + throw new InternalError(encoding+" encoding not found", e);
145.9 }
145.10 serverSocket.setTcpNoDelay(true);
145.11 }
146.1 --- a/src/share/classes/sun/net/www/protocol/gopher/GopherClient.java Thu Sep 15 18:53:28 2011 -0700
146.2 +++ b/src/share/classes/sun/net/www/protocol/gopher/GopherClient.java Mon Sep 19 19:40:59 2011 -0700
146.3 @@ -324,7 +324,7 @@
146.4 }
146.5
146.6 } catch (UnsupportedEncodingException e) {
146.7 - throw new InternalError(encoding+ " encoding not found");
146.8 + throw new InternalError(encoding+ " encoding not found", e);
146.9 } catch (IOException e) {
146.10 } finally {
146.11 try {
147.1 --- a/src/share/classes/sun/net/www/protocol/https/HttpsClient.java Thu Sep 15 18:53:28 2011 -0700
147.2 +++ b/src/share/classes/sun/net/www/protocol/https/HttpsClient.java Mon Sep 19 19:40:59 2011 -0700
147.3 @@ -529,7 +529,7 @@
147.4 new BufferedOutputStream(serverSocket.getOutputStream()),
147.5 false, encoding);
147.6 } catch (UnsupportedEncodingException e) {
147.7 - throw new InternalError(encoding+" encoding not found");
147.8 + throw new InternalError(encoding+" encoding not found", e);
147.9 }
147.10
147.11 // check URL spoofing if it has not been checked under handshaking
148.1 --- a/src/share/classes/sun/nio/ch/Util.java Thu Sep 15 18:53:28 2011 -0700
148.2 +++ b/src/share/classes/sun/nio/ch/Util.java Mon Sep 19 19:40:59 2011 -0700
148.3 @@ -373,7 +373,7 @@
148.4 NoSuchMethodException |
148.5 IllegalArgumentException |
148.6 ClassCastException x) {
148.7 - throw new InternalError();
148.8 + throw new InternalError(x);
148.9 }
148.10 return null;
148.11 }});
148.12 @@ -395,7 +395,7 @@
148.13 } catch (InstantiationException |
148.14 IllegalAccessException |
148.15 InvocationTargetException e) {
148.16 - throw new InternalError();
148.17 + throw new InternalError(e);
148.18 }
148.19 return dbb;
148.20 }
148.21 @@ -418,7 +418,7 @@
148.22 NoSuchMethodException |
148.23 IllegalArgumentException |
148.24 ClassCastException x) {
148.25 - throw new InternalError();
148.26 + throw new InternalError(x);
148.27 }
148.28 return null;
148.29 }});
148.30 @@ -440,7 +440,7 @@
148.31 } catch (InstantiationException |
148.32 IllegalAccessException |
148.33 InvocationTargetException e) {
148.34 - throw new InternalError();
148.35 + throw new InternalError(e);
148.36 }
148.37 return dbb;
148.38 }
149.1 --- a/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java Thu Sep 15 18:53:28 2011 -0700
149.2 +++ b/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java Mon Sep 19 19:40:59 2011 -0700
149.3 @@ -179,7 +179,9 @@
149.4
149.5 public Charset next() {
149.6 String csn = i.next();
149.7 - return lookup(csn);
149.8 + synchronized (AbstractCharsetProvider.this) {
149.9 + return lookup(csn);
149.10 + }
149.11 }
149.12
149.13 public void remove() {
150.1 --- a/src/share/classes/sun/reflect/UTF8.java Thu Sep 15 18:53:28 2011 -0700
150.2 +++ b/src/share/classes/sun/reflect/UTF8.java Mon Sep 19 19:40:59 2011 -0700
150.3 @@ -52,7 +52,7 @@
150.4 }
150.5 } catch (ArrayIndexOutOfBoundsException e) {
150.6 throw new InternalError
150.7 - ("Bug in sun.reflect bootstrap UTF-8 encoder");
150.8 + ("Bug in sun.reflect bootstrap UTF-8 encoder", e);
150.9 }
150.10 return res;
150.11 }
151.1 --- a/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java Thu Sep 15 18:53:28 2011 -0700
151.2 +++ b/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java Mon Sep 19 19:40:59 2011 -0700
151.3 @@ -25,9 +25,11 @@
151.4
151.5 package sun.reflect.generics.reflectiveObjects;
151.6
151.7 +import java.lang.annotation.Annotation;
151.8 import java.lang.reflect.GenericDeclaration;
151.9 import java.lang.reflect.Type;
151.10 import java.lang.reflect.TypeVariable;
151.11 +import java.util.Objects;
151.12
151.13 import sun.reflect.generics.factory.GenericsFactory;
151.14 import sun.reflect.generics.tree.FieldTypeSignature;
151.15 @@ -178,4 +180,27 @@
151.16 public int hashCode() {
151.17 return genericDeclaration.hashCode() ^ name.hashCode();
151.18 }
151.19 +
151.20 + // Currently vacuous implementations of AnnotatedElement methods.
151.21 + public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
151.22 + Objects.requireNonNull(annotationClass);
151.23 + return false;
151.24 + }
151.25 +
151.26 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
151.27 + Objects.requireNonNull(annotationClass);
151.28 + return null;
151.29 + }
151.30 +
151.31 + public Annotation[] getAnnotations() {
151.32 + // Since zero-length, don't need defensive clone
151.33 + return EMPTY_ANNOTATION_ARRAY;
151.34 + }
151.35 +
151.36 + public Annotation[] getDeclaredAnnotations() {
151.37 + // Since zero-length, don't need defensive clone
151.38 + return EMPTY_ANNOTATION_ARRAY;
151.39 + }
151.40 +
151.41 + private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
151.42 }
152.1 --- a/src/share/classes/sun/reflect/misc/MethodUtil.java Thu Sep 15 18:53:28 2011 -0700
152.2 +++ b/src/share/classes/sun/reflect/misc/MethodUtil.java Mon Sep 19 19:40:59 2011 -0700
152.3 @@ -292,7 +292,7 @@
152.4 }
152.5 });
152.6 } catch (Exception e) {
152.7 - throw new InternalError("bouncer cannot be found");
152.8 + throw new InternalError("bouncer cannot be found", e);
152.9 }
152.10 }
152.11
153.1 --- a/src/share/classes/sun/rmi/transport/LiveRef.java Thu Sep 15 18:53:28 2011 -0700
153.2 +++ b/src/share/classes/sun/rmi/transport/LiveRef.java Mon Sep 19 19:40:59 2011 -0700
153.3 @@ -111,7 +111,7 @@
153.4 LiveRef newRef = (LiveRef) super.clone();
153.5 return newRef;
153.6 } catch (CloneNotSupportedException e) {
153.7 - throw new InternalError(e.toString());
153.8 + throw new InternalError(e.toString(), e);
153.9 }
153.10 }
153.11
154.1 --- a/src/share/classes/sun/security/krb5/EncryptionKey.java Thu Sep 15 18:53:28 2011 -0700
154.2 +++ b/src/share/classes/sun/security/krb5/EncryptionKey.java Mon Sep 19 19:40:59 2011 -0700
154.3 @@ -151,11 +151,36 @@
154.4 }
154.5
154.6 /**
154.7 + * Obtains a key for a given etype of a principal with possible new salt
154.8 + * and s2kparams
154.9 + * @param cname NOT null
154.10 + * @param password NOT null
154.11 + * @param etype
154.12 + * @param snp can be NULL
154.13 + * @returns never null
154.14 + */
154.15 + public static EncryptionKey acquireSecretKey(PrincipalName cname,
154.16 + char[] password, int etype, PAData.SaltAndParams snp)
154.17 + throws KrbException {
154.18 + String salt;
154.19 + byte[] s2kparams;
154.20 + if (snp != null) {
154.21 + salt = snp.salt != null ? snp.salt : cname.getSalt();
154.22 + s2kparams = snp.params;
154.23 + } else {
154.24 + salt = cname.getSalt();
154.25 + s2kparams = null;
154.26 + }
154.27 + return acquireSecretKey(password, salt, etype, s2kparams);
154.28 + }
154.29 +
154.30 + /**
154.31 * Obtains a key for a given etype with salt and optional s2kparams
154.32 * @param password NOT null
154.33 * @param salt NOT null
154.34 * @param etype
154.35 * @param s2kparams can be NULL
154.36 + * @returns never null
154.37 */
154.38 public static EncryptionKey acquireSecretKey(char[] password,
154.39 String salt, int etype, byte[] s2kparams)
155.1 --- a/src/share/classes/sun/security/krb5/KrbAsRep.java Thu Sep 15 18:53:28 2011 -0700
155.2 +++ b/src/share/classes/sun/security/krb5/KrbAsRep.java Mon Sep 19 19:40:59 2011 -0700
155.3 @@ -131,13 +131,11 @@
155.4 KrbAsReq asReq, PrincipalName cname)
155.5 throws KrbException, Asn1Exception, IOException {
155.6 int encPartKeyType = rep.encPart.getEType();
155.7 - PAData.SaltAndParams snp =
155.8 - PAData.getSaltAndParams(encPartKeyType, rep.pAData);
155.9 - EncryptionKey dkey = null;
155.10 - dkey = EncryptionKey.acquireSecretKey(password,
155.11 - snp.salt == null ? cname.getSalt() : snp.salt,
155.12 + EncryptionKey dkey = EncryptionKey.acquireSecretKey(
155.13 + cname,
155.14 + password,
155.15 encPartKeyType,
155.16 - snp.params);
155.17 + PAData.getSaltAndParams(encPartKeyType, rep.pAData));
155.18 decrypt(dkey, asReq);
155.19 }
155.20
156.1 --- a/src/share/classes/sun/security/krb5/KrbAsReqBuilder.java Thu Sep 15 18:53:28 2011 -0700
156.2 +++ b/src/share/classes/sun/security/krb5/KrbAsReqBuilder.java Mon Sep 19 19:40:59 2011 -0700
156.3 @@ -169,34 +169,44 @@
156.4 * from a keytab on acceptor, but unfortunately (?) Java supports
156.5 * acceptor using password. In this case, if the service ticket is
156.6 * encrypted using an etype which we don't have PA-DATA new salt,
156.7 - * using the default salt is normally wrong (say, case-insensitive
156.8 + * using the default salt might be wrong (say, case-insensitive
156.9 * user name). Instead, we would use the new salt of another etype.
156.10 */
156.11
156.12 String salt = null; // the saved new salt
156.13 - for (int i=0; i<eTypes.length; i++) {
156.14 - PAData.SaltAndParams snp =
156.15 - PAData.getSaltAndParams(eTypes[i], paList);
156.16 - // First round, only calculate those with new salt
156.17 - if (snp.salt != null) {
156.18 - salt = snp.salt;
156.19 - result[i] = EncryptionKey.acquireSecretKey(password,
156.20 - snp.salt,
156.21 - eTypes[i],
156.22 - snp.params);
156.23 - }
156.24 - }
156.25 - if (salt == null) salt = cname.getSalt();
156.26 - for (int i=0; i<eTypes.length; i++) {
156.27 - // Second round, calculate those with no new salt
156.28 - if (result[i] == null) {
156.29 + try {
156.30 + for (int i=0; i<eTypes.length; i++) {
156.31 + // First round, only calculate those have a PA entry
156.32 PAData.SaltAndParams snp =
156.33 PAData.getSaltAndParams(eTypes[i], paList);
156.34 - result[i] = EncryptionKey.acquireSecretKey(password,
156.35 - salt,
156.36 - eTypes[i],
156.37 - snp.params);
156.38 + if (snp != null) {
156.39 + // Never uses a salt for rc4-hmac, it does not use
156.40 + // a salt at all
156.41 + if (eTypes[i] != EncryptedData.ETYPE_ARCFOUR_HMAC &&
156.42 + snp.salt != null) {
156.43 + salt = snp.salt;
156.44 + }
156.45 + result[i] = EncryptionKey.acquireSecretKey(cname,
156.46 + password,
156.47 + eTypes[i],
156.48 + snp);
156.49 + }
156.50 }
156.51 + // No new salt from PA, maybe empty, maybe only rc4-hmac
156.52 + if (salt == null) salt = cname.getSalt();
156.53 + for (int i=0; i<eTypes.length; i++) {
156.54 + // Second round, calculate those with no PA entry
156.55 + if (result[i] == null) {
156.56 + result[i] = EncryptionKey.acquireSecretKey(password,
156.57 + salt,
156.58 + eTypes[i],
156.59 + null);
156.60 + }
156.61 + }
156.62 + } catch (IOException ioe) {
156.63 + KrbException ke = new KrbException(Krb5.ASN1_PARSE_ERROR);
156.64 + ke.initCause(ioe);
156.65 + throw ke;
156.66 }
156.67 return result;
156.68 } else {
156.69 @@ -315,27 +325,19 @@
156.70 }
156.71 preAuthFailedOnce = true;
156.72 KRBError kerr = ke.getError();
156.73 + int paEType = PAData.getPreferredEType(kerr.getPA(),
156.74 + EType.getDefaults("default_tkt_enctypes")[0]);
156.75 if (password == null) {
156.76 EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
156.77 - pakey = EncryptionKey.findKey(kerr.getEType(), ks);
156.78 + pakey = EncryptionKey.findKey(paEType, ks);
156.79 if (pakey != null) pakey = (EncryptionKey)pakey.clone();
156.80 for (EncryptionKey k: ks) k.destroy();
156.81 } else {
156.82 - PAData.SaltAndParams snp = PAData.getSaltAndParams(
156.83 - kerr.getEType(), kerr.getPA());
156.84 - if (kerr.getEType() == 0) {
156.85 - // Possible if PA-PW-SALT is in KRB-ERROR. RFC
156.86 - // does not recommend this
156.87 - pakey = EncryptionKey.acquireSecretKey(password,
156.88 - snp.salt == null ? cname.getSalt() : snp.salt,
156.89 - EType.getDefaults("default_tkt_enctypes")[0],
156.90 - null);
156.91 - } else {
156.92 - pakey = EncryptionKey.acquireSecretKey(password,
156.93 - snp.salt == null ? cname.getSalt() : snp.salt,
156.94 - kerr.getEType(),
156.95 - snp.params);
156.96 - }
156.97 + pakey = EncryptionKey.acquireSecretKey(cname,
156.98 + password,
156.99 + paEType,
156.100 + PAData.getSaltAndParams(
156.101 + paEType, kerr.getPA()));
156.102 }
156.103 paList = kerr.getPA(); // Update current paList
156.104 } else {
157.1 --- a/src/share/classes/sun/security/krb5/internal/KRBError.java Thu Sep 15 18:53:28 2011 -0700
157.2 +++ b/src/share/classes/sun/security/krb5/internal/KRBError.java Mon Sep 19 19:40:59 2011 -0700
157.3 @@ -99,7 +99,6 @@
157.4 private Checksum eCksum; //optional
157.5
157.6 private PAData[] pa; // PA-DATA in eData
157.7 - private int pa_eType; // The 1st etype appeared in salt-related PAData
157.8
157.9 private static boolean DEBUG = Krb5.DEBUG;
157.10
157.11 @@ -266,50 +265,8 @@
157.12 DerValue tmp = derPA.data.getDerValue();
157.13 PAData pa_data = new PAData(tmp);
157.14 paList.add(pa_data);
157.15 - int pa_type = pa_data.getType();
157.16 - byte[] pa_value = pa_data.getValue();
157.17 if (DEBUG) {
157.18 - System.out.println(">>>Pre-Authentication Data:");
157.19 - System.out.println("\t PA-DATA type = " + pa_type);
157.20 - }
157.21 -
157.22 - switch(pa_type) {
157.23 - case Krb5.PA_ENC_TIMESTAMP:
157.24 - if (DEBUG) {
157.25 - System.out.println("\t PA-ENC-TIMESTAMP");
157.26 - }
157.27 - break;
157.28 - case Krb5.PA_ETYPE_INFO:
157.29 - if (pa_value != null) {
157.30 - DerValue der = new DerValue(pa_value);
157.31 - while (der.data.available() > 0) {
157.32 - DerValue value = der.data.getDerValue();
157.33 - ETypeInfo info = new ETypeInfo(value);
157.34 - if (pa_eType == 0) pa_eType = info.getEType();
157.35 - if (DEBUG) {
157.36 - System.out.println("\t PA-ETYPE-INFO etype = " + info.getEType());
157.37 - System.out.println("\t PA-ETYPE-INFO salt = " + info.getSalt());
157.38 - }
157.39 - }
157.40 - }
157.41 - break;
157.42 - case Krb5.PA_ETYPE_INFO2:
157.43 - if (pa_value != null) {
157.44 - DerValue der = new DerValue(pa_value);
157.45 - while (der.data.available() > 0) {
157.46 - DerValue value = der.data.getDerValue();
157.47 - ETypeInfo2 info2 = new ETypeInfo2(value);
157.48 - if (pa_eType == 0) pa_eType = info2.getEType();
157.49 - if (DEBUG) {
157.50 - System.out.println("\t PA-ETYPE-INFO2 etype = " + info2.getEType());
157.51 - System.out.println("\t PA-ETYPE-INFO2 salt = " + info2.getSalt());
157.52 - }
157.53 - }
157.54 - }
157.55 - break;
157.56 - default:
157.57 - // Unknown Pre-auth type
157.58 - break;
157.59 + System.out.println(pa_data);
157.60 }
157.61 }
157.62 pa = paList.toArray(new PAData[paList.size()]);
157.63 @@ -340,10 +297,6 @@
157.64 return pa;
157.65 }
157.66
157.67 - public final int getEType() {
157.68 - return pa_eType;
157.69 - }
157.70 -
157.71 public final String getErrorString() {
157.72 return eText;
157.73 }
158.1 --- a/src/share/classes/sun/security/krb5/internal/PAData.java Thu Sep 15 18:53:28 2011 -0700
158.2 +++ b/src/share/classes/sun/security/krb5/internal/PAData.java Mon Sep 19 19:40:59 2011 -0700
158.3 @@ -139,9 +139,56 @@
158.4 }
158.5
158.6 /**
158.7 + * Gets the preferred etype from the PAData array.
158.8 + * 1. ETYPE-INFO2-ENTRY with unknown s2kparams ignored
158.9 + * 2. ETYPE-INFO2 preferred to ETYPE-INFO
158.10 + * 3. multiple entries for same etype in one PA-DATA, use the first one.
158.11 + * 4. Multiple PA-DATA with same type, choose the last one
158.12 + * (This is useful when PA-DATAs from KRB-ERROR and AS-REP are combined).
158.13 + * @return the etype, or defaultEType if not enough info
158.14 + * @throws Asn1Exception|IOException if there is an encoding error
158.15 + */
158.16 + public static int getPreferredEType(PAData[] pas, int defaultEType)
158.17 + throws IOException, Asn1Exception {
158.18 +
158.19 + if (pas == null) return defaultEType;
158.20 +
158.21 + DerValue d = null, d2 = null;
158.22 + for (PAData p: pas) {
158.23 + if (p.getValue() == null) continue;
158.24 + switch (p.getType()) {
158.25 + case Krb5.PA_ETYPE_INFO:
158.26 + d = new DerValue(p.getValue());
158.27 + break;
158.28 + case Krb5.PA_ETYPE_INFO2:
158.29 + d2 = new DerValue(p.getValue());
158.30 + break;
158.31 + }
158.32 + }
158.33 + if (d2 != null) {
158.34 + while (d2.data.available() > 0) {
158.35 + DerValue value = d2.data.getDerValue();
158.36 + ETypeInfo2 tmp = new ETypeInfo2(value);
158.37 + if (tmp.getParams() == null) {
158.38 + // we don't support non-null s2kparams
158.39 + return tmp.getEType();
158.40 + }
158.41 + }
158.42 + }
158.43 + if (d != null) {
158.44 + while (d.data.available() > 0) {
158.45 + DerValue value = d.data.getDerValue();
158.46 + ETypeInfo tmp = new ETypeInfo(value);
158.47 + return tmp.getEType();
158.48 + }
158.49 + }
158.50 + return defaultEType;
158.51 + }
158.52 +
158.53 + /**
158.54 * A place to store a pair of salt and s2kparams.
158.55 - * An empty salt is changed to null, to be interopable
158.56 - * with Windows 2000 server.
158.57 + * An empty salt is changed to null, to be interoperable
158.58 + * with Windows 2000 server. This is in fact not correct.
158.59 */
158.60 public static class SaltAndParams {
158.61 public final String salt;
158.62 @@ -155,57 +202,120 @@
158.63
158.64 /**
158.65 * Fetches salt and s2kparams value for eType in a series of PA-DATAs.
158.66 - * The preference order is PA-ETYPE-INFO2 > PA-ETYPE-INFO > PA-PW-SALT.
158.67 - * If multiple PA-DATA for the same etype appears, use the last one.
158.68 + * 1. ETYPE-INFO2-ENTRY with unknown s2kparams ignored
158.69 + * 2. PA-ETYPE-INFO2 preferred to PA-ETYPE-INFO preferred to PA-PW-SALT.
158.70 + * 3. multiple entries for same etype in one PA-DATA, use the first one.
158.71 + * 4. Multiple PA-DATA with same type, choose the last one
158.72 * (This is useful when PA-DATAs from KRB-ERROR and AS-REP are combined).
158.73 - * @return salt and s2kparams. never null, its field might be null.
158.74 + * @return salt and s2kparams. can be null if not found
158.75 */
158.76 public static SaltAndParams getSaltAndParams(int eType, PAData[] pas)
158.77 - throws Asn1Exception, KrbException {
158.78 + throws Asn1Exception, IOException {
158.79
158.80 - if (pas == null || pas.length == 0) {
158.81 - return new SaltAndParams(null, null);
158.82 - }
158.83 + if (pas == null) return null;
158.84
158.85 + DerValue d = null, d2 = null;
158.86 String paPwSalt = null;
158.87 - ETypeInfo2 info2 = null;
158.88 - ETypeInfo info = null;
158.89
158.90 for (PAData p: pas) {
158.91 - if (p.getValue() != null) {
158.92 - try {
158.93 - switch (p.getType()) {
158.94 - case Krb5.PA_PW_SALT:
158.95 - paPwSalt = new String(p.getValue(),
158.96 - KerberosString.MSNAME?"UTF8":"8859_1");
158.97 - break;
158.98 - case Krb5.PA_ETYPE_INFO:
158.99 - DerValue der = new DerValue(p.getValue());
158.100 - while (der.data.available() > 0) {
158.101 - DerValue value = der.data.getDerValue();
158.102 - ETypeInfo tmp = new ETypeInfo(value);
158.103 - if (tmp.getEType() == eType) info = tmp;
158.104 - }
158.105 - break;
158.106 - case Krb5.PA_ETYPE_INFO2:
158.107 - der = new DerValue(p.getValue());
158.108 - while (der.data.available() > 0) {
158.109 - DerValue value = der.data.getDerValue();
158.110 - ETypeInfo2 tmp = new ETypeInfo2(value);
158.111 - if (tmp.getEType() == eType) info2 = tmp;
158.112 - }
158.113 - break;
158.114 - }
158.115 - } catch (IOException ioe) {
158.116 - // Ignored
158.117 + if (p.getValue() == null) continue;
158.118 + switch (p.getType()) {
158.119 + case Krb5.PA_PW_SALT:
158.120 + paPwSalt = new String(p.getValue(),
158.121 + KerberosString.MSNAME?"UTF8":"8859_1");
158.122 + break;
158.123 + case Krb5.PA_ETYPE_INFO:
158.124 + d = new DerValue(p.getValue());
158.125 + break;
158.126 + case Krb5.PA_ETYPE_INFO2:
158.127 + d2 = new DerValue(p.getValue());
158.128 + break;
158.129 + }
158.130 + }
158.131 + if (d2 != null) {
158.132 + while (d2.data.available() > 0) {
158.133 + DerValue value = d2.data.getDerValue();
158.134 + ETypeInfo2 tmp = new ETypeInfo2(value);
158.135 + if (tmp.getParams() == null && tmp.getEType() == eType) {
158.136 + // we don't support non-null s2kparams
158.137 + return new SaltAndParams(tmp.getSalt(), tmp.getParams());
158.138 }
158.139 }
158.140 }
158.141 - if (info2 != null) {
158.142 - return new SaltAndParams(info2.getSalt(), info2.getParams());
158.143 - } else if (info != null) {
158.144 - return new SaltAndParams(info.getSalt(), null);
158.145 + if (d != null) {
158.146 + while (d.data.available() > 0) {
158.147 + DerValue value = d.data.getDerValue();
158.148 + ETypeInfo tmp = new ETypeInfo(value);
158.149 + if (tmp.getEType() == eType) {
158.150 + return new SaltAndParams(tmp.getSalt(), null);
158.151 + }
158.152 + }
158.153 }
158.154 - return new SaltAndParams(paPwSalt, null);
158.155 + if (paPwSalt != null) {
158.156 + return new SaltAndParams(paPwSalt, null);
158.157 + }
158.158 + return null;
158.159 + }
158.160 +
158.161 + @Override
158.162 + public String toString(){
158.163 + StringBuilder sb = new StringBuilder();
158.164 + sb.append(">>>Pre-Authentication Data:\n\t PA-DATA type = ")
158.165 + .append(pADataType).append('\n');
158.166 +
158.167 + switch(pADataType) {
158.168 + case Krb5.PA_ENC_TIMESTAMP:
158.169 + sb.append("\t PA-ENC-TIMESTAMP");
158.170 + break;
158.171 + case Krb5.PA_ETYPE_INFO:
158.172 + if (pADataValue != null) {
158.173 + try {
158.174 + DerValue der = new DerValue(pADataValue);
158.175 + while (der.data.available() > 0) {
158.176 + DerValue value = der.data.getDerValue();
158.177 + ETypeInfo info = new ETypeInfo(value);
158.178 + sb.append("\t PA-ETYPE-INFO etype = ")
158.179 + .append(info.getEType())
158.180 + .append(", salt = ")
158.181 + .append(info.getSalt())
158.182 + .append('\n');
158.183 + }
158.184 + } catch (IOException|Asn1Exception e) {
158.185 + sb.append("\t <Unparseable PA-ETYPE-INFO>\n");
158.186 + }
158.187 + }
158.188 + break;
158.189 + case Krb5.PA_ETYPE_INFO2:
158.190 + if (pADataValue != null) {
158.191 + try {
158.192 + DerValue der = new DerValue(pADataValue);
158.193 + while (der.data.available() > 0) {
158.194 + DerValue value = der.data.getDerValue();
158.195 + ETypeInfo2 info2 = new ETypeInfo2(value);
158.196 + sb.append("\t PA-ETYPE-INFO2 etype = ")
158.197 + .append(info2.getEType())
158.198 + .append(", salt = ")
158.199 + .append(info2.getSalt())
158.200 + .append(", s2kparams = ");
158.201 + byte[] s2kparams = info2.getParams();
158.202 + if (s2kparams == null) {
158.203 + sb.append("null\n");
158.204 + } else if (s2kparams.length == 0) {
158.205 + sb.append("empty\n");
158.206 + } else {
158.207 + sb.append(new sun.misc.HexDumpEncoder()
158.208 + .encodeBuffer(s2kparams));
158.209 + }
158.210 + }
158.211 + } catch (IOException|Asn1Exception e) {
158.212 + sb.append("\t <Unparseable PA-ETYPE-INFO>\n");
158.213 + }
158.214 + }
158.215 + break;
158.216 + default:
158.217 + // Unknown Pre-auth type
158.218 + break;
158.219 + }
158.220 + return sb.toString();
158.221 }
158.222 }
159.1 --- a/src/share/classes/sun/security/provider/SecureRandom.java Thu Sep 15 18:53:28 2011 -0700
159.2 +++ b/src/share/classes/sun/security/provider/SecureRandom.java Mon Sep 19 19:40:59 2011 -0700
159.3 @@ -249,7 +249,7 @@
159.4 try {
159.5 digest = MessageDigest.getInstance ("SHA");
159.6 } catch (NoSuchAlgorithmException e) {
159.7 - throw new InternalError("internal error: SHA-1 not available.");
159.8 + throw new InternalError("internal error: SHA-1 not available.", e);
159.9 }
159.10 }
159.11 }
160.1 --- a/src/share/classes/sun/security/provider/SeedGenerator.java Thu Sep 15 18:53:28 2011 -0700
160.2 +++ b/src/share/classes/sun/security/provider/SeedGenerator.java Mon Sep 19 19:40:59 2011 -0700
160.3 @@ -151,7 +151,8 @@
160.4 try {
160.5 md = MessageDigest.getInstance("SHA");
160.6 } catch (NoSuchAlgorithmException nsae) {
160.7 - throw new InternalError("internal error: SHA-1 not available.");
160.8 + throw new InternalError("internal error: SHA-1 not available."
160.9 + , nsae);
160.10 }
160.11
160.12 // The current time in millis
160.13 @@ -258,7 +259,8 @@
160.14 try {
160.15 digest = MessageDigest.getInstance("SHA");
160.16 } catch (NoSuchAlgorithmException e) {
160.17 - throw new InternalError("internal error: SHA-1 not available.");
160.18 + throw new InternalError("internal error: SHA-1 not available."
160.19 + , e);
160.20 }
160.21
160.22 final ThreadGroup[] finalsg = new ThreadGroup[1];
160.23 @@ -311,7 +313,8 @@
160.24 t.start();
160.25 } catch (Exception e) {
160.26 throw new InternalError("internal error: " +
160.27 - "SeedGenerator thread creation error.");
160.28 + "SeedGenerator thread creation error."
160.29 + , e);
160.30 }
160.31
160.32 // We wait 250milli quanta, so the minimum wait time
160.33 @@ -344,7 +347,8 @@
160.34 }
160.35 } catch (Exception e) {
160.36 throw new InternalError("internal error: " +
160.37 - "SeedGenerator thread generated an exception.");
160.38 + "SeedGenerator thread generated an exception."
160.39 + , e);
160.40 }
160.41 }
160.42
160.43 @@ -367,7 +371,8 @@
160.44 } catch (Exception e) {
160.45 if (count <= 0)
160.46 throw new InternalError("internal error: " +
160.47 - "SeedGenerator thread generated an exception.");
160.48 + "SeedGenerator thread generated an exception."
160.49 + ,e);
160.50 }
160.51
160.52 synchronized(this) {
160.53 @@ -533,7 +538,7 @@
160.54 } catch (IOException ioe) {
160.55 throw new InternalError("URLSeedGenerator " + deviceName +
160.56 " generated exception: " +
160.57 - ioe.getMessage());
160.58 + ioe.getMessage(), ioe);
160.59 }
160.60 }
160.61
161.1 --- a/src/share/classes/sun/security/provider/certpath/ForwardState.java Thu Sep 15 18:53:28 2011 -0700
161.2 +++ b/src/share/classes/sun/security/provider/certpath/ForwardState.java Mon Sep 19 19:40:59 2011 -0700
161.3 @@ -262,7 +262,7 @@
161.4 = (HashSet<GeneralNameInterface>)subjectNamesTraversed.clone();
161.5 return clonedState;
161.6 } catch (CloneNotSupportedException e) {
161.7 - throw new InternalError(e.toString());
161.8 + throw new InternalError(e.toString(), e);
161.9 }
161.10 }
161.11 }
162.1 --- a/src/share/classes/sun/security/provider/certpath/ReverseState.java Thu Sep 15 18:53:28 2011 -0700
162.2 +++ b/src/share/classes/sun/security/provider/certpath/ReverseState.java Mon Sep 19 19:40:59 2011 -0700
162.3 @@ -394,7 +394,7 @@
162.4
162.5 return clonedState;
162.6 } catch (CloneNotSupportedException e) {
162.7 - throw new InternalError(e.toString());
162.8 + throw new InternalError(e.toString(), e);
162.9 }
162.10 }
162.11 }
163.1 --- a/src/share/classes/sun/security/provider/certpath/URICertStore.java Thu Sep 15 18:53:28 2011 -0700
163.2 +++ b/src/share/classes/sun/security/provider/certpath/URICertStore.java Mon Sep 19 19:40:59 2011 -0700
163.3 @@ -494,7 +494,7 @@
163.4 return super.clone();
163.5 } catch (CloneNotSupportedException e) {
163.6 /* Cannot happen */
163.7 - throw new InternalError(e.toString());
163.8 + throw new InternalError(e.toString(), e);
163.9 }
163.10 }
163.11 }
164.1 --- a/src/share/classes/sun/security/tools/JarSigner.java Thu Sep 15 18:53:28 2011 -0700
164.2 +++ b/src/share/classes/sun/security/tools/JarSigner.java Mon Sep 19 19:40:59 2011 -0700
164.3 @@ -1506,6 +1506,9 @@
164.4 CertPath cp = certificateFactory.generateCertPath(certs);
164.5 validator.validate(cp, pkixParameters);
164.6 } catch (Exception e) {
164.7 + if (debug) {
164.8 + e.printStackTrace();
164.9 + }
164.10 chainNotValidated = true;
164.11 s.append(tab + rb.getString(".CertPath.not.validated.") +
164.12 e.getLocalizedMessage() + "]\n"); // TODO
164.13 @@ -1562,6 +1565,27 @@
164.14 }
164.15
164.16 try {
164.17 +
164.18 + certificateFactory = CertificateFactory.getInstance("X.509");
164.19 + validator = CertPathValidator.getInstance("PKIX");
164.20 + Set<TrustAnchor> tas = new HashSet<>();
164.21 + try {
164.22 + KeyStore caks = KeyTool.getCacertsKeyStore();
164.23 + if (caks != null) {
164.24 + Enumeration<String> aliases = caks.aliases();
164.25 + while (aliases.hasMoreElements()) {
164.26 + String a = aliases.nextElement();
164.27 + try {
164.28 + tas.add(new TrustAnchor((X509Certificate)caks.getCertificate(a), null));
164.29 + } catch (Exception e2) {
164.30 + // ignore, when a SecretkeyEntry does not include a cert
164.31 + }
164.32 + }
164.33 + }
164.34 + } catch (Exception e) {
164.35 + // Ignore, if cacerts cannot be loaded
164.36 + }
164.37 +
164.38 if (providerName == null) {
164.39 store = KeyStore.getInstance(storetype);
164.40 } else {
164.41 @@ -1580,45 +1604,28 @@
164.42 (rb.getString("Enter.Passphrase.for.keystore."));
164.43 }
164.44
164.45 - if (nullStream) {
164.46 - store.load(null, storepass);
164.47 - } else {
164.48 - keyStoreName = keyStoreName.replace(File.separatorChar, '/');
164.49 - URL url = null;
164.50 - try {
164.51 - url = new URL(keyStoreName);
164.52 - } catch (java.net.MalformedURLException e) {
164.53 - // try as file
164.54 - url = new File(keyStoreName).toURI().toURL();
164.55 - }
164.56 - InputStream is = null;
164.57 - try {
164.58 - is = url.openStream();
164.59 - store.load(is, storepass);
164.60 - } finally {
164.61 - if (is != null) {
164.62 - is.close();
164.63 + try {
164.64 + if (nullStream) {
164.65 + store.load(null, storepass);
164.66 + } else {
164.67 + keyStoreName = keyStoreName.replace(File.separatorChar, '/');
164.68 + URL url = null;
164.69 + try {
164.70 + url = new URL(keyStoreName);
164.71 + } catch (java.net.MalformedURLException e) {
164.72 + // try as file
164.73 + url = new File(keyStoreName).toURI().toURL();
164.74 }
164.75 - }
164.76 - }
164.77 - Set<TrustAnchor> tas = new HashSet<>();
164.78 - try {
164.79 - KeyStore caks = KeyTool.getCacertsKeyStore();
164.80 - if (caks != null) {
164.81 - Enumeration<String> aliases = caks.aliases();
164.82 - while (aliases.hasMoreElements()) {
164.83 - String a = aliases.nextElement();
164.84 - try {
164.85 - tas.add(new TrustAnchor((X509Certificate)caks.getCertificate(a), null));
164.86 - } catch (Exception e2) {
164.87 - // ignore, when a SecretkeyEntry does not include a cert
164.88 + InputStream is = null;
164.89 + try {
164.90 + is = url.openStream();
164.91 + store.load(is, storepass);
164.92 + } finally {
164.93 + if (is != null) {
164.94 + is.close();
164.95 }
164.96 }
164.97 }
164.98 - } catch (Exception e) {
164.99 - // Ignore, if cacerts cannot be loaded
164.100 - }
164.101 - if (store != null) {
164.102 Enumeration<String> aliases = store.aliases();
164.103 while (aliases.hasMoreElements()) {
164.104 String a = aliases.nextElement();
164.105 @@ -1634,14 +1641,13 @@
164.106 // ignore, when a SecretkeyEntry does not include a cert
164.107 }
164.108 }
164.109 - }
164.110 - certificateFactory = CertificateFactory.getInstance("X.509");
164.111 - validator = CertPathValidator.getInstance("PKIX");
164.112 - try {
164.113 - pkixParameters = new PKIXParameters(tas);
164.114 - pkixParameters.setRevocationEnabled(false);
164.115 - } catch (InvalidAlgorithmParameterException ex) {
164.116 - // Only if tas is empty
164.117 + } finally {
164.118 + try {
164.119 + pkixParameters = new PKIXParameters(tas);
164.120 + pkixParameters.setRevocationEnabled(false);
164.121 + } catch (InvalidAlgorithmParameterException ex) {
164.122 + // Only if tas is empty
164.123 + }
164.124 }
164.125 } catch (IOException ioe) {
164.126 throw new RuntimeException(rb.getString("keystore.load.") +
164.127 @@ -1805,6 +1811,9 @@
164.128 CertPath cp = certificateFactory.generateCertPath(Arrays.asList(certChain));
164.129 validator.validate(cp, pkixParameters);
164.130 } catch (Exception e) {
164.131 + if (debug) {
164.132 + e.printStackTrace();
164.133 + }
164.134 chainNotValidated = true;
164.135 }
164.136
165.1 --- a/src/share/classes/sun/security/tools/KeyTool.java Thu Sep 15 18:53:28 2011 -0700
165.2 +++ b/src/share/classes/sun/security/tools/KeyTool.java Mon Sep 19 19:40:59 2011 -0700
165.3 @@ -1141,17 +1141,14 @@
165.4 if (token) {
165.5 keyStore.store(null, null);
165.6 } else {
165.7 - FileOutputStream fout = null;
165.8 - try {
165.9 - fout = (nullStream ?
165.10 - (FileOutputStream)null :
165.11 - new FileOutputStream(ksfname));
165.12 - keyStore.store
165.13 - (fout,
165.14 - (storePassNew!=null) ? storePassNew : storePass);
165.15 - } finally {
165.16 - if (fout != null) {
165.17 - fout.close();
165.18 + char[] pass = (storePassNew!=null) ? storePassNew : storePass;
165.19 + if (nullStream) {
165.20 + keyStore.store(null, pass);
165.21 + } else {
165.22 + ByteArrayOutputStream bout = new ByteArrayOutputStream();
165.23 + keyStore.store(bout, pass);
165.24 + try (FileOutputStream fout = new FileOutputStream(ksfname)) {
165.25 + fout.write(bout.toByteArray());
165.26 }
165.27 }
165.28 }
165.29 @@ -1399,7 +1396,7 @@
165.30 private char[] promptForKeyPass(String alias, String orig, char[] origPass) throws Exception{
165.31 if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
165.32 return origPass;
165.33 - } else if (!token) {
165.34 + } else if (!token && !protectedPath) {
165.35 // Prompt for key password
165.36 int count;
165.37 for (count = 0; count < 3; count++) {
165.38 @@ -1446,7 +1443,7 @@
165.39 }
165.40 }
165.41 }
165.42 - return null; // PKCS11
165.43 + return null; // PKCS11, MSCAPI, or -protected
165.44 }
165.45 /**
165.46 * Creates a new secret key.
166.1 --- a/src/share/classes/sun/security/util/SecurityConstants.java Thu Sep 15 18:53:28 2011 -0700
166.2 +++ b/src/share/classes/sun/security/util/SecurityConstants.java Mon Sep 19 19:40:59 2011 -0700
166.3 @@ -127,10 +127,8 @@
166.4 // AWT present
166.5 try {
166.6 return (PermissionFactory<?>)c.newInstance();
166.7 - } catch (InstantiationException x) {
166.8 - throw new InternalError(x.getMessage());
166.9 - } catch (IllegalAccessException x) {
166.10 - throw new InternalError(x.getMessage());
166.11 + } catch (ReflectiveOperationException x) {
166.12 + throw new InternalError(x.getMessage(), x);
166.13 }
166.14 } else {
166.15 // AWT not present
167.1 --- a/src/share/classes/sun/text/CompactByteArray.java Thu Sep 15 18:53:28 2011 -0700
167.2 +++ b/src/share/classes/sun/text/CompactByteArray.java Mon Sep 19 19:40:59 2011 -0700
167.3 @@ -269,7 +269,7 @@
167.4 if (hashes != null) other.hashes = (int[])hashes.clone();
167.5 return other;
167.6 } catch (CloneNotSupportedException e) {
167.7 - throw new InternalError();
167.8 + throw new InternalError(e);
167.9 }
167.10 }
167.11
168.1 --- a/src/share/classes/sun/text/normalizer/NormalizerBase.java Thu Sep 15 18:53:28 2011 -0700
168.2 +++ b/src/share/classes/sun/text/normalizer/NormalizerBase.java Mon Sep 19 19:40:59 2011 -0700
168.3 @@ -636,7 +636,7 @@
168.4 return copy;
168.5 }
168.6 catch (CloneNotSupportedException e) {
168.7 - throw new InternalError(e.toString());
168.8 + throw new InternalError(e.toString(), e);
168.9 }
168.10 }
168.11
169.1 --- a/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java Thu Sep 15 18:53:28 2011 -0700
169.2 +++ b/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java Mon Sep 19 19:40:59 2011 -0700
169.3 @@ -89,7 +89,7 @@
169.4 if (t instanceof SecurityException) {
169.5 return result;
169.6 }
169.7 - throw new InternalError(); // shouldn't happen
169.8 + throw new InternalError(t); // shouldn't happen
169.9 }
169.10
169.11 for (Object vmid: vms) {
170.1 --- a/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java Thu Sep 15 18:53:28 2011 -0700
170.2 +++ b/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java Mon Sep 19 19:40:59 2011 -0700
170.3 @@ -102,7 +102,7 @@
170.4 try {
170.5 loadAgentLibrary("instrument", args);
170.6 } catch (AgentLoadException x) {
170.7 - throw new InternalError("instrument library is missing in target VM");
170.8 + throw new InternalError("instrument library is missing in target VM", x);
170.9 } catch (AgentInitializationException x) {
170.10 /*
170.11 * Translate interesting errors into the right exception and
170.12 @@ -212,7 +212,7 @@
170.13 try {
170.14 return execute(cmd, args);
170.15 } catch (AgentLoadException x) {
170.16 - throw new InternalError("Should not get here");
170.17 + throw new InternalError("Should not get here", x);
170.18 }
170.19 }
170.20
171.1 --- a/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java Thu Sep 15 18:53:28 2011 -0700
171.2 +++ b/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java Mon Sep 19 19:40:59 2011 -0700
171.3 @@ -135,10 +135,8 @@
171.4 try {
171.5 host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
171.6 vms = host.activeVms();
171.7 - } catch (java.net.URISyntaxException sx) {
171.8 - throw new InternalError(sx.getMessage());
171.9 - } catch (MonitorException mx) {
171.10 - throw new InternalError(mx.getMessage());
171.11 + } catch (java.net.URISyntaxException | MonitorException x) {
171.12 + throw new InternalError(x.getMessage(), x);
171.13 }
171.14 for (Object vmid: vms) {
171.15 if (vmid instanceof Integer) {
172.1 --- a/src/share/classes/sun/tools/tree/Node.java Thu Sep 15 18:53:28 2011 -0700
172.2 +++ b/src/share/classes/sun/tools/tree/Node.java Mon Sep 19 19:40:59 2011 -0700
172.3 @@ -108,7 +108,7 @@
172.4 return super.clone();
172.5 } catch (CloneNotSupportedException e) {
172.6 // this shouldn't happen, since we are Cloneable
172.7 - throw new InternalError();
172.8 + throw new InternalError(e);
172.9 }
172.10 }
172.11
173.1 --- a/src/share/classes/sun/tracing/dtrace/DTraceProvider.java Thu Sep 15 18:53:28 2011 -0700
173.2 +++ b/src/share/classes/sun/tracing/dtrace/DTraceProvider.java Mon Sep 19 19:40:59 2011 -0700
173.3 @@ -26,18 +26,15 @@
173.4 package sun.tracing.dtrace;
173.5
173.6 import java.lang.reflect.Method;
173.7 -import java.lang.reflect.InvocationTargetException;
173.8 import java.lang.reflect.Modifier;
173.9 import java.lang.reflect.Constructor;
173.10 import java.lang.reflect.InvocationHandler;
173.11 import java.lang.reflect.InvocationTargetException;
173.12 import java.lang.annotation.Annotation;
173.13 -import java.util.HashMap;
173.14
173.15 import sun.tracing.ProviderSkeleton;
173.16 import sun.tracing.ProbeSkeleton;
173.17 import com.sun.tracing.Provider;
173.18 -import com.sun.tracing.ProviderName;
173.19 import com.sun.tracing.ProbeName;
173.20 import com.sun.tracing.dtrace.Attributes;
173.21 import com.sun.tracing.dtrace.ModuleName;
173.22 @@ -140,14 +137,8 @@
173.23 try {
173.24 Constructor cons = proxyClass.getConstructor(constructorParams);
173.25 return (T)cons.newInstance(new Object[] { this });
173.26 - } catch (NoSuchMethodException e) {
173.27 - throw new InternalError(e.toString());
173.28 - } catch (IllegalAccessException e) {
173.29 - throw new InternalError(e.toString());
173.30 - } catch (InstantiationException e) {
173.31 - throw new InternalError(e.toString());
173.32 - } catch (InvocationTargetException e) {
173.33 - throw new InternalError(e.toString());
173.34 + } catch (ReflectiveOperationException e) {
173.35 + throw new InternalError(e.toString(), e);
173.36 }
173.37 }
173.38
174.1 --- a/src/share/classes/sun/util/calendar/CalendarDate.java Thu Sep 15 18:53:28 2011 -0700
174.2 +++ b/src/share/classes/sun/util/calendar/CalendarDate.java Mon Sep 19 19:40:59 2011 -0700
174.3 @@ -435,7 +435,7 @@
174.4 return super.clone();
174.5 } catch (CloneNotSupportedException e) {
174.6 // this shouldn't happen
174.7 - throw new InternalError();
174.8 + throw new InternalError(e);
174.9 }
174.10 }
174.11
175.1 --- a/src/solaris/classes/sun/awt/X11/XBaseMenuWindow.java Thu Sep 15 18:53:28 2011 -0700
175.2 +++ b/src/solaris/classes/sun/awt/X11/XBaseMenuWindow.java Mon Sep 19 19:40:59 2011 -0700
175.3 @@ -157,7 +157,7 @@
175.4 try {
175.5 return super.clone();
175.6 } catch (CloneNotSupportedException ex) {
175.7 - throw new InternalError();
175.8 + throw new InternalError(ex);
175.9 }
175.10 }
175.11
176.1 --- a/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java Thu Sep 15 18:53:28 2011 -0700
176.2 +++ b/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java Mon Sep 19 19:40:59 2011 -0700
176.3 @@ -131,7 +131,7 @@
176.4 try {
176.5 return super.clone();
176.6 } catch (CloneNotSupportedException ex) {
176.7 - throw new InternalError();
176.8 + throw new InternalError(ex);
176.9 }
176.10 }
176.11
177.1 --- a/src/solaris/classes/sun/nio/ch/InheritedChannel.java Thu Sep 15 18:53:28 2011 -0700
177.2 +++ b/src/solaris/classes/sun/nio/ch/InheritedChannel.java Mon Sep 19 19:40:59 2011 -0700
177.3 @@ -64,7 +64,7 @@
177.4 dup2(devnull, 2);
177.5 } catch (IOException ioe) {
177.6 // this shouldn't happen
177.7 - throw new InternalError();
177.8 + throw new InternalError(ioe);
177.9 }
177.10 }
177.11
178.1 --- a/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java Thu Sep 15 18:53:28 2011 -0700
178.2 +++ b/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java Mon Sep 19 19:40:59 2011 -0700
178.3 @@ -304,7 +304,7 @@
178.4 try {
178.5 b = s.getBytes("UTF-8");
178.6 } catch (java.io.UnsupportedEncodingException x) {
178.7 - throw new InternalError();
178.8 + throw new InternalError(x);
178.9 }
178.10 LinuxVirtualMachine.write(fd, b, 0, b.length);
178.11 }
179.1 --- a/src/solaris/native/sun/awt/fontpath.c Thu Sep 15 18:53:28 2011 -0700
179.2 +++ b/src/solaris/native/sun/awt/fontpath.c Mon Sep 19 19:40:59 2011 -0700
179.3 @@ -1191,8 +1191,16 @@
179.4
179.5 fontformat = NULL;
179.6 (*FcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat);
179.7 - if (fontformat != NULL && strcmp((char*)fontformat, "TrueType")
179.8 - != 0) {
179.9 + /* We only want TrueType fonts but some Linuxes still depend
179.10 + * on Type 1 fonts for some Locale support, so we'll allow
179.11 + * them there.
179.12 + */
179.13 + if (fontformat != NULL
179.14 + && (strcmp((char*)fontformat, "TrueType") != 0)
179.15 +#ifdef __linux__
179.16 + && (strcmp((char*)fontformat, "Type 1") != 0)
179.17 +#endif
179.18 + ) {
179.19 continue;
179.20 }
179.21 result = (*FcPatternGetCharSet)(fontPattern,
180.1 --- a/src/windows/native/com/sun/security/auth/module/nt.c Thu Sep 15 18:53:28 2011 -0700
180.2 +++ b/src/windows/native/com/sun/security/auth/module/nt.c Mon Sep 19 19:40:59 2011 -0700
180.3 @@ -1,5 +1,5 @@
180.4 /*
180.5 - * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
180.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
180.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
180.8 *
180.9 * This code is free software; you can redistribute it and/or modify it
180.10 @@ -43,6 +43,19 @@
180.11 BOOL getTextualSid(PSID pSid, LPTSTR TextualSid, LPDWORD lpdwBufferLen);
180.12 void DisplayErrorText(DWORD dwLastError);
180.13
180.14 +JNIEXPORT jlong JNICALL
180.15 +Java_com_sun_security_auth_module_NTSystem_getImpersonationToken0
180.16 + (JNIEnv *env, jobject obj) {
180.17 + HANDLE impersonationToken = 0; // impersonation token
180.18 + if (debug) {
180.19 + printf("getting impersonation token\n");
180.20 + }
180.21 + if (getImpersonationToken(&impersonationToken) == FALSE) {
180.22 + return 0;
180.23 + }
180.24 + return (jlong)impersonationToken;
180.25 +}
180.26 +
180.27 JNIEXPORT void JNICALL
180.28 Java_com_sun_security_auth_module_NTSystem_getCurrent
180.29 (JNIEnv *env, jobject obj, jboolean debugNative) {
180.30 @@ -59,7 +72,6 @@
180.31 DWORD numGroups = 0; // num groups
180.32 LPTSTR *groups = NULL; // groups array
180.33 long pIndex = -1; // index of primaryGroup in groups array
180.34 - HANDLE impersonationToken = 0; // impersonation token
180.35
180.36 jfieldID fid;
180.37 jstring jstr;
180.38 @@ -100,13 +112,6 @@
180.39 return;
180.40 }
180.41
180.42 - if (debug) {
180.43 - printf("getting impersonation token\n");
180.44 - }
180.45 - if (getImpersonationToken(&impersonationToken) == FALSE) {
180.46 - return;
180.47 - }
180.48 -
180.49 // then set values into NTSystem
180.50
180.51 fid = (*env)->GetFieldID(env, cls, "userName", "Ljava/lang/String;");
180.52 @@ -233,18 +238,6 @@
180.53 (*env)->SetObjectField(env, obj, fid, jgroups);
180.54 }
180.55
180.56 - fid = (*env)->GetFieldID(env, cls, "impersonationToken", "J");
180.57 - if (fid == 0) {
180.58 - jclass newExcCls =
180.59 - (*env)->FindClass(env, "java/lang/IllegalArgumentException");
180.60 - if (newExcCls == 0) {
180.61 - systemError = TRUE;
180.62 - goto out;
180.63 - }
180.64 - (*env)->ThrowNew(env, newExcCls, "invalid field: impersonationToken");
180.65 - }
180.66 - (*env)->SetLongField(env, obj, fid, (jlong)impersonationToken);
180.67 -
180.68 out:
180.69 if (userName != NULL) {
180.70 HeapFree(GetProcessHeap(), 0, userName);
180.71 @@ -269,6 +262,7 @@
180.72 }
180.73 HeapFree(GetProcessHeap(), 0, groups);
180.74 }
180.75 + CloseHandle(tokenHandle);
180.76
180.77 if (systemError && debug) {
180.78 printf(" [getCurrent] System Error: ");
180.79 @@ -592,6 +586,7 @@
180.80 }
180.81 return FALSE;
180.82 }
180.83 + CloseHandle(dupToken);
180.84
180.85 if (debug) {
180.86 printf(" [getImpersonationToken] token = %d\n", *impersonationToken);
180.87 @@ -802,6 +797,8 @@
180.88 }
180.89 HeapFree(GetProcessHeap(), 0, groups);
180.90 }
180.91 + CloseHandle(impersonationToken);
180.92 + CloseHandle(tokenHandle);
180.93 }
180.94 */
180.95
181.1 --- a/src/windows/native/java/net/NetworkInterface.c Thu Sep 15 18:53:28 2011 -0700
181.2 +++ b/src/windows/native/java/net/NetworkInterface.c Mon Sep 19 19:40:59 2011 -0700
181.3 @@ -504,8 +504,7 @@
181.4 */
181.5 if (netaddrCount < 0) {
181.6 netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
181.7 - if ((*env)->ExceptionOccurred(env)) {
181.8 - free_netaddr(netaddrP);
181.9 + if (netaddrCount == -1) {
181.10 return NULL;
181.11 }
181.12 }
182.1 --- a/src/windows/native/java/net/NetworkInterface_winXP.c Thu Sep 15 18:53:28 2011 -0700
182.2 +++ b/src/windows/native/java/net/NetworkInterface_winXP.c Mon Sep 19 19:40:59 2011 -0700
182.3 @@ -194,8 +194,7 @@
182.4 while (curr != NULL) {
182.5 netaddr *netaddrP;
182.6 ret = enumAddresses_win(env, curr, &netaddrP);
182.7 - if ((*env)->ExceptionOccurred(env)) {
182.8 - free_netaddr(netaddrP);
182.9 + if (ret == -1) {
182.10 return -1;
182.11 }
182.12 curr->addrs = netaddrP;
182.13 @@ -449,8 +448,7 @@
182.14 */
182.15 if (netaddrCount < 0) {
182.16 netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
182.17 - if ((*env)->ExceptionOccurred(env)) {
182.18 - free_netaddr(netaddrP);
182.19 + if (netaddrCount == -1) {
182.20 return NULL;
182.21 }
182.22 }
183.1 --- a/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Thu Sep 15 18:53:28 2011 -0700
183.2 +++ b/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Mon Sep 19 19:40:59 2011 -0700
183.3 @@ -576,6 +576,7 @@
183.4 {
183.5 /* fields on this */
183.6 jint port;
183.7 + jint scope;
183.8 jint timeout = (*env)->GetIntField(env, this, psi_timeoutID);
183.9 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
183.10 jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
183.11 @@ -755,7 +756,11 @@
183.12 addr = (*env)->GetObjectField (env, socketAddressObj, ia6_ipaddressID);
183.13 (*env)->SetByteArrayRegion (env, addr, 0, 16, (const char *)&him.him6.sin6_addr);
183.14 (*env)->SetIntField(env, socketAddressObj, ia_familyID, IPv6);
183.15 - (*env)->SetIntField(env, socketAddressObj, ia6_scopeidID, him.him6.sin6_scope_id);
183.16 + scope = him.him6.sin6_scope_id;
183.17 + (*env)->SetIntField(env, socketAddressObj, ia6_scopeidID, scope);
183.18 + if(scope>0) {
183.19 + (*env)->SetBooleanField(env, socketAddressObj, ia6_scopeidsetID, JNI_TRUE);
183.20 + }
183.21 }
183.22 /* fields common to AF_INET and AF_INET6 */
183.23
184.1 --- a/src/windows/native/sun/windows/awt_FileDialog.cpp Thu Sep 15 18:53:28 2011 -0700
184.2 +++ b/src/windows/native/sun/windows/awt_FileDialog.cpp Mon Sep 19 19:40:59 2011 -0700
184.3 @@ -153,6 +153,11 @@
184.4 break;
184.5 }
184.6 case WM_DESTROY: {
184.7 + HIMC hIMC = ::ImmGetContext(hdlg);
184.8 + if (hIMC != NULL) {
184.9 + ::ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
184.10 + }
184.11 +
184.12 WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(parent, NativeDialogWndProcProp));
184.13 ComCtl32Util::GetInstance().UnsubclassHWND(parent,
184.14 FileDialogWndProc,
185.1 --- a/test/Makefile Thu Sep 15 18:53:28 2011 -0700
185.2 +++ b/test/Makefile Mon Sep 19 19:40:59 2011 -0700
185.3 @@ -423,7 +423,8 @@
185.4 # Stable othervm testruns (minus items from PROBLEM_LIST)
185.5 # Using samevm has problems, and doesn't help performance as much as others.
185.6 JDK_ALL_TARGETS += jdk_awt
185.7 -jdk_awt: $(call TestDirs, com/sun/awt java/awt sun/awt)
185.8 +jdk_awt: $(call TestDirs, com/sun/awt java/awt sun/awt \
185.9 + javax/imageio javax/print sun/pisces)
185.10 $(call RunOthervmBatch)
185.11
185.12 # Stable samevm testruns (minus items from PROBLEM_LIST)
185.13 @@ -486,9 +487,8 @@
185.14 # Stable samevm testruns (minus items from PROBLEM_LIST)
185.15 JDK_ALL_TARGETS += jdk_misc
185.16 jdk_misc: $(call TestDirs, \
185.17 - demo javax/imageio javax/naming javax/print javax/script \
185.18 - javax/smartcardio javax/sound com/sun/java com/sun/jndi \
185.19 - com/sun/org com/sun/xml sun/misc sun/pisces)
185.20 + demo/jvmti demo/zipfs javax/naming javax/script \
185.21 + javax/smartcardio com/sun/jndi com/sun/xml sun/misc)
185.22 $(call RunSamevmBatch)
185.23
185.24 # Stable samevm testruns (minus items from PROBLEM_LIST)
185.25 @@ -532,17 +532,15 @@
185.26 jdk_security1: $(call TestDirs, java/security)
185.27 $(call RunSamevmBatch)
185.28
185.29 -# Stable othervm testruns (minus items from PROBLEM_LIST)
185.30 -# Using samevm has serious problems with these tests
185.31 +# Stable samevm testruns (minus items from PROBLEM_LIST)
185.32 JDK_ALL_TARGETS += jdk_security2
185.33 -jdk_security2: $(call TestDirs, javax/crypto com/sun/crypto)
185.34 +jdk_security2: $(call TestDirs, javax/crypto javax/xml/crypto com/sun/crypto)
185.35 $(call RunSamevmBatch)
185.36
185.37 -# Stable othervm testruns (minus items from PROBLEM_LIST)
185.38 -# Using samevm has serious problems with these tests
185.39 +# Stable samevm testruns (minus items from PROBLEM_LIST)
185.40 JDK_ALL_TARGETS += jdk_security3
185.41 -jdk_security3: $(call TestDirs, com/sun/security lib/security \
185.42 - javax/security sun/security)
185.43 +jdk_security3: $(call TestDirs, com/sun/security lib/security javax/security \
185.44 + sun/security com/sun/org/apache/xml/internal/security)
185.45 $(call SharedLibraryPermissions,sun/security)
185.46 $(call RunSamevmBatch)
185.47
185.48 @@ -550,10 +548,16 @@
185.49 jdk_security: jdk_security1 jdk_security2 jdk_security3
185.50 @$(SummaryInfo)
185.51
185.52 +# Stable samevm testruns (minus items from PROBLEM_LIST)
185.53 +JDK_ALL_TARGETS += jdk_sound
185.54 +jdk_sound: $(call TestDirs, javax/sound)
185.55 + $(call RunSamevmBatch)
185.56 +
185.57 # Stable othervm testruns (minus items from PROBLEM_LIST)
185.58 # Using samevm has problems, and doesn't help performance as much as others.
185.59 JDK_ALL_TARGETS += jdk_swing
185.60 -jdk_swing: $(call TestDirs, javax/swing sun/java2d)
185.61 +jdk_swing: $(call TestDirs, javax/swing sun/java2d \
185.62 + demo/jfc com/sun/java/swing)
185.63 $(call RunOthervmBatch)
185.64
185.65 # Stable samevm testruns (minus items from PROBLEM_LIST)
185.66 @@ -802,17 +806,17 @@
185.67 # The jtjck.jar utility to use to run the tests
185.68 JTJCK_JAR = $(JCK_HOME)/lib/jtjck.jar
185.69 JTJCK_JAVA_ARGS = -XX:MaxPermSize=256m -Xmx512m
185.70 -JTJCK_OPTIONS = -headless -v
185.71 +JTJCK_OPTIONS = -headless -v
185.72
185.73 # Default tests to run
185.74 ifndef JCK_COMPILER_TESTS
185.75 - JCK_COMPILER_TESTS =
185.76 + JCK_COMPILER_TESTS =
185.77 endif
185.78 ifndef JCK_RUNTIME_TESTS
185.79 - JCK_RUNTIME_TESTS =
185.80 + JCK_RUNTIME_TESTS =
185.81 endif
185.82 ifndef JCK_DEVTOOLS_TESTS
185.83 - JCK_DEVTOOLS_TESTS =
185.84 + JCK_DEVTOOLS_TESTS =
185.85 endif
185.86
185.87 # Generic rule used to run jck tests
185.88 @@ -838,14 +842,14 @@
185.89 _generic_jck_tests
185.90
185.91 # JCK7 runtime tests
185.92 -jck7runtime:
185.93 +jck7runtime:
185.94 $(MAKE) UNIQUE_DIR=$@ \
185.95 JCK_HOME=$(JCK7RUNTIME_HOME) \
185.96 TESTDIRS="$(JCK_RUNTIME_TESTS)" \
185.97 _generic_jck_tests
185.98
185.99 # JCK7 devtools tests
185.100 -jck7devtools:
185.101 +jck7devtools:
185.102 $(MAKE) UNIQUE_DIR=$@ \
185.103 JCK_HOME=$(JCK7DEVTOOLS_HOME) \
185.104 TESTDIRS="$(JCK_DEVTOOLS_TESTS)" \
186.1 --- a/test/ProblemList.txt Thu Sep 15 18:53:28 2011 -0700
186.2 +++ b/test/ProblemList.txt Mon Sep 19 19:40:59 2011 -0700
186.3 @@ -526,6 +526,16 @@
186.4 # 7081817
186.5 sun/security/provider/certpath/X509CertPath/IllegalCertiticates.java generic-all
186.6
186.7 +# 7041639, Solaris DSA keypair generation bug (Note: jdk_util also affected)
186.8 +java/security/KeyPairGenerator/SolarisShortDSA.java solaris-all
186.9 +sun/security/tools/jarsigner/onlymanifest.sh solaris-all
186.10 +sun/security/tools/jarsigner/ts.sh solaris-all
186.11 +sun/security/tools/keytool/emptysubject.sh solaris-all
186.12 +sun/security/tools/keytool/importreadall.sh solaris-all
186.13 +sun/security/tools/keytool/readjar.sh solaris-all
186.14 +sun/security/tools/keytool/selfissued.sh solaris-all
186.15 +sun/security/tools/keytool/standard.sh solaris-all
186.16 +
186.17 ############################################################################
186.18
186.19 # jdk_swing (not using samevm)
186.20 @@ -586,5 +596,8 @@
186.21 # Filed 6772009
186.22 java/util/concurrent/locks/ReentrantLock/CancelledLockLoops.java generic-all
186.23
186.24 +# 7041639, Solaris DSA keypair generation bug
186.25 +java/util/TimeZone/TimeZoneDatePermissionCheck.sh solaris-all
186.26 +
186.27 ############################################################################
186.28
187.1 --- a/test/com/sun/servicetag/JavaServiceTagTest.java Thu Sep 15 18:53:28 2011 -0700
187.2 +++ b/test/com/sun/servicetag/JavaServiceTagTest.java Mon Sep 19 19:40:59 2011 -0700
187.3 @@ -25,7 +25,7 @@
187.4
187.5 /*
187.6 * @test
187.7 - * @bug 6622366
187.8 + * @bug 6622366 7078024
187.9 * @summary Basic Test for ServiceTag.getJavaServiceTag()
187.10 * Disable creating the service tag in the system registry.
187.11 * Verify the existence of registration.xml file and the
187.12 @@ -86,23 +86,42 @@
187.13 }
187.14 }
187.15
187.16 + /**
187.17 + * Tests if the running platform is a JDK.
187.18 + */
187.19 + static boolean isJDK() {
187.20 + // Determine the JRE path by checking the existence of
187.21 + // <HOME>/jre/lib and <HOME>/lib.
187.22 + String javaHome = System.getProperty("java.home");
187.23 + String jrepath = javaHome + File.separator + "jre";
187.24 + File f = new File(jrepath, "lib");
187.25 + if (!f.exists()) {
187.26 + // java.home usually points to the JRE path
187.27 + jrepath = javaHome;
187.28 + }
187.29 +
187.30 + return jrepath.endsWith(File.separator + "jre");
187.31 + }
187.32 +
187.33 private static void checkServiceTag(ServiceTag st) throws IOException {
187.34 - Properties props = loadSwordfishEntries();
187.35 - if (st.getProductURN().
187.36 - equals(props.getProperty("servicetag.jdk.urn"))) {
187.37 - if (!st.getProductName().
187.38 - equals(props.getProperty("servicetag.jdk.name"))) {
187.39 - throw new RuntimeException("Product URN and name don't match.");
187.40 - }
187.41 - } else if (st.getProductURN().
187.42 - equals(props.getProperty("servicetag.jre.urn"))) {
187.43 - if (!st.getProductName().
187.44 - equals(props.getProperty("servicetag.jre.name"))) {
187.45 + Properties props = loadServiceTagProps();
187.46 + // jdk 8 and later, JDK and JRE have the same product URN.
187.47 + String jdkUrn = props.getProperty("servicetag.jdk.urn");
187.48 + String jreUrn = props.getProperty("servicetag.jre.urn");
187.49 + boolean isJdk = isJDK();
187.50 +
187.51 + if (isJdk) {
187.52 + if (!st.getProductURN().equals(jdkUrn) ||
187.53 + !st.getProductName().equals(
187.54 + props.getProperty("servicetag.jdk.name"))) {
187.55 throw new RuntimeException("Product URN and name don't match.");
187.56 }
187.57 } else {
187.58 - throw new RuntimeException("Unexpected product_urn: " +
187.59 - st.getProductURN());
187.60 + if (!st.getProductURN().equals(jreUrn) ||
187.61 + !st.getProductName().equals(
187.62 + props.getProperty("servicetag.jre.name"))) {
187.63 + throw new RuntimeException("Product URN and name don't match.");
187.64 + }
187.65 }
187.66 if (!st.getProductVersion().
187.67 equals(System.getProperty("java.version"))) {
187.68 @@ -160,18 +179,13 @@
187.69 }
187.70 }
187.71
187.72 - private static Properties loadSwordfishEntries()
187.73 + private static Properties loadServiceTagProps()
187.74 throws IOException {
187.75 - int version = sun.misc.Version.jdkMinorVersion();
187.76 - String filename = "/com/sun/servicetag/resources/javase_" +
187.77 - version + "_swordfish.properties";
187.78 - InputStream in = Installer.class.getClass().getResourceAsStream(filename);
187.79 - Properties props = new Properties();
187.80 - try {
187.81 + String filename = "/com/sun/servicetag/resources/javase_servicetag.properties";
187.82 + try (InputStream in = Installer.class.getClass().getResourceAsStream(filename)) {
187.83 + Properties props = new Properties();
187.84 props.load(in);
187.85 - } finally {
187.86 - in.close();
187.87 + return props;
187.88 }
187.89 - return props;
187.90 }
187.91 }
188.1 --- a/test/com/sun/servicetag/JavaServiceTagTest1.java Thu Sep 15 18:53:28 2011 -0700
188.2 +++ b/test/com/sun/servicetag/JavaServiceTagTest1.java Mon Sep 19 19:40:59 2011 -0700
188.3 @@ -25,7 +25,7 @@
188.4
188.5 /*
188.6 * @test
188.7 - * @bug 6622366
188.8 + * @bug 6622366 7078024
188.9 * @summary Basic Test for ServiceTag.getJavaServiceTag(String)
188.10 * to verify that the registration.xml and servicetag files
188.11 * are both created correctly.
188.12 @@ -157,25 +157,45 @@
188.13 return svctag;
188.14 }
188.15
188.16 + /**
188.17 + * Tests if the running platform is a JDK.
188.18 + */
188.19 + static boolean isJDK() {
188.20 + // Determine the JRE path by checking the existence of
188.21 + // <HOME>/jre/lib and <HOME>/lib.
188.22 + String javaHome = System.getProperty("java.home");
188.23 + String jrepath = javaHome + File.separator + "jre";
188.24 + File f = new File(jrepath, "lib");
188.25 + if (!f.exists()) {
188.26 + // java.home usually points to the JRE path
188.27 + jrepath = javaHome;
188.28 + }
188.29 +
188.30 + return jrepath.endsWith(File.separator + "jre");
188.31 + }
188.32 +
188.33 private static void checkServiceTag(ServiceTag st, String source)
188.34 throws IOException {
188.35 - Properties props = loadSwordfishEntries();
188.36 - if (st.getProductURN().
188.37 - equals(props.getProperty("servicetag.jdk.urn"))) {
188.38 - if (!st.getProductName().
188.39 - equals(props.getProperty("servicetag.jdk.name"))) {
188.40 - throw new RuntimeException("Product URN and name don't match.");
188.41 - }
188.42 - } else if (st.getProductURN().
188.43 - equals(props.getProperty("servicetag.jre.urn"))) {
188.44 - if (!st.getProductName().
188.45 - equals(props.getProperty("servicetag.jre.name"))) {
188.46 + Properties props = loadServiceTagProps();
188.47 + // jdk 8 and later, JDK and JRE have the same product URN.
188.48 + String jdkUrn = props.getProperty("servicetag.jdk.urn");
188.49 + String jreUrn = props.getProperty("servicetag.jre.urn");
188.50 + boolean isJdk = isJDK();
188.51 +
188.52 + if (isJdk) {
188.53 + if (!st.getProductURN().equals(jdkUrn) ||
188.54 + !st.getProductName().equals(
188.55 + props.getProperty("servicetag.jdk.name"))) {
188.56 throw new RuntimeException("Product URN and name don't match.");
188.57 }
188.58 } else {
188.59 - throw new RuntimeException("Unexpected product_urn: " +
188.60 - st.getProductURN());
188.61 + if (!st.getProductURN().equals(jreUrn) ||
188.62 + !st.getProductName().equals(
188.63 + props.getProperty("servicetag.jre.name"))) {
188.64 + throw new RuntimeException("Product URN and name don't match.");
188.65 + }
188.66 }
188.67 +
188.68 if (!st.getProductVersion().
188.69 equals(System.getProperty("java.version"))) {
188.70 throw new RuntimeException("Unexpected product_version: " +
188.71 @@ -233,18 +253,13 @@
188.72 }
188.73 }
188.74
188.75 - private static Properties loadSwordfishEntries()
188.76 + private static Properties loadServiceTagProps()
188.77 throws IOException {
188.78 - int version = sun.misc.Version.jdkMinorVersion();
188.79 - String filename = "/com/sun/servicetag/resources/javase_" +
188.80 - version + "_swordfish.properties";
188.81 - InputStream in = Installer.class.getClass().getResourceAsStream(filename);
188.82 - Properties props = new Properties();
188.83 - try {
188.84 + String filename = "/com/sun/servicetag/resources/javase_servicetag.properties";
188.85 + try (InputStream in = Installer.class.getClass().getResourceAsStream(filename)) {
188.86 + Properties props = new Properties();
188.87 props.load(in);
188.88 - } finally {
188.89 - in.close();
188.90 + return props;
188.91 }
188.92 - return props;
188.93 }
188.94 }
189.1 --- a/test/java/lang/invoke/InvokeGenericTest.java Thu Sep 15 18:53:28 2011 -0700
189.2 +++ b/test/java/lang/invoke/InvokeGenericTest.java Mon Sep 19 19:40:59 2011 -0700
189.3 @@ -25,7 +25,7 @@
189.4
189.5 /* @test
189.6 * @summary unit tests for java.lang.invoke.MethodHandle.invoke
189.7 - * @compile -target 7 InvokeGenericTest.java
189.8 + * @compile InvokeGenericTest.java
189.9 * @run junit/othervm test.java.lang.invoke.InvokeGenericTest
189.10 */
189.11
190.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
190.2 +++ b/test/java/lang/reflect/TypeVariable/TestAnnotatedElement.java Mon Sep 19 19:40:59 2011 -0700
190.3 @@ -0,0 +1,88 @@
190.4 +/*
190.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
190.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
190.7 + *
190.8 + * This code is free software; you can redistribute it and/or modify it
190.9 + * under the terms of the GNU General Public License version 2 only, as
190.10 + * published by the Free Software Foundation.
190.11 + *
190.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
190.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
190.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
190.15 + * version 2 for more details (a copy is included in the LICENSE file that
190.16 + * accompanied this code).
190.17 + *
190.18 + * You should have received a copy of the GNU General Public License version
190.19 + * 2 along with this work; if not, write to the Free Software Foundation,
190.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
190.21 + *
190.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
190.23 + * or visit www.oracle.com if you need additional information or have any
190.24 + * questions.
190.25 + */
190.26 +
190.27 +/*
190.28 + * @test
190.29 + * @bug 7086192
190.30 + * @summary Verify functionality of AnnotatedElement methods on type variables
190.31 + * @author Joseph D. Darcy
190.32 + */
190.33 +
190.34 +import java.lang.reflect.*;
190.35 +import java.lang.annotation.*;
190.36 +
190.37 +public class TestAnnotatedElement<A> {
190.38 + // Type variable on a method
190.39 + private static <B> B m(B b) {return null;}
190.40 +
190.41 + // Type variable on a construtor
190.42 + private <C> TestAnnotatedElement(){super();}
190.43 +
190.44 + public static void main(String... argv) throws ReflectiveOperationException {
190.45 + int errors = 0;
190.46 +
190.47 + Class<?> clazz = TestAnnotatedElement.class;
190.48 + errors += testTypeVariable(clazz.getTypeParameters());
190.49 + errors += testTypeVariable(clazz.getDeclaredConstructor().getTypeParameters());
190.50 + errors += testTypeVariable(clazz.getDeclaredMethod("m", Object.class).getTypeParameters());
190.51 +
190.52 + if (errors > 0)
190.53 + throw new RuntimeException(errors + " failures");
190.54 + }
190.55 +
190.56 +
190.57 + private static int testTypeVariable(TypeVariable<?>[] typeVars) {
190.58 + int errors = 0;
190.59 + if (typeVars.length == 0)
190.60 + return ++errors;
190.61 +
190.62 + for(TypeVariable<?> typeVar : typeVars) {
190.63 + try {
190.64 + typeVar.getAnnotation(null);
190.65 + errors++;
190.66 + } catch(NullPointerException npe) {
190.67 + ; // Expected
190.68 + }
190.69 +
190.70 + if (typeVar.getAnnotation(SuppressWarnings.class) != null)
190.71 + errors++;
190.72 +
190.73 + try {
190.74 + typeVar.isAnnotationPresent(null);
190.75 + errors++;
190.76 + } catch(NullPointerException npe) {
190.77 + ; // Expected
190.78 + }
190.79 +
190.80 + if (typeVar.isAnnotationPresent(SuppressWarnings.class))
190.81 + errors++;
190.82 +
190.83 + if(typeVar.getAnnotations().length != 0)
190.84 + errors++;
190.85 +
190.86 + if(typeVar.getDeclaredAnnotations().length != 0)
190.87 + errors++;
190.88 + }
190.89 + return errors;
190.90 + }
190.91 +}
191.1 --- a/test/java/math/BigDecimal/DivideMcTests.java Thu Sep 15 18:53:28 2011 -0700
191.2 +++ b/test/java/math/BigDecimal/DivideMcTests.java Mon Sep 19 19:40:59 2011 -0700
191.3 @@ -1,5 +1,5 @@
191.4 /*
191.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
191.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
191.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
191.8 *
191.9 * This code is free software; you can redistribute it and/or modify it
192.1 --- a/test/java/math/BigDecimal/FloatDoubleValueTests.java Thu Sep 15 18:53:28 2011 -0700
192.2 +++ b/test/java/math/BigDecimal/FloatDoubleValueTests.java Mon Sep 19 19:40:59 2011 -0700
192.3 @@ -1,5 +1,5 @@
192.4 /*
192.5 - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
192.6 + * Copyright (c) 2005, 2011 Oracle and/or its affiliates. All rights reserved.
192.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
192.8 *
192.9 * This code is free software; you can redistribute it and/or modify it
192.10 @@ -23,7 +23,7 @@
192.11
192.12 /*
192.13 * @test
192.14 - * @bug 6274390
192.15 + * @bug 6274390 7082971
192.16 * @summary Verify {float, double}Value methods work with condensed representation
192.17 * @run main FloatDoubleValueTests
192.18 * @run main/othervm -XX:+AggressiveOpts FloatDoubleValueTests
192.19 @@ -79,6 +79,7 @@
192.20 // and double.
192.21 static void testFloatDoubleValue() {
192.22 long longValues[] = {
192.23 + Long.MIN_VALUE, // -2^63
192.24 0,
192.25 1,
192.26 2,
193.1 --- a/test/java/math/BigDecimal/RangeTests.java Thu Sep 15 18:53:28 2011 -0700
193.2 +++ b/test/java/math/BigDecimal/RangeTests.java Mon Sep 19 19:40:59 2011 -0700
193.3 @@ -1,5 +1,5 @@
193.4 /*
193.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
193.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
193.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
193.8 *
193.9 * This code is free software; you can redistribute it and/or modify it
194.1 --- a/test/java/math/BigDecimal/StrippingZerosTest.java Thu Sep 15 18:53:28 2011 -0700
194.2 +++ b/test/java/math/BigDecimal/StrippingZerosTest.java Mon Sep 19 19:40:59 2011 -0700
194.3 @@ -1,5 +1,5 @@
194.4 /*
194.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
194.6 + * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
194.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
194.8 *
194.9 * This code is free software; you can redistribute it and/or modify it
195.1 --- a/test/java/math/BigDecimal/ToPlainStringTests.java Thu Sep 15 18:53:28 2011 -0700
195.2 +++ b/test/java/math/BigDecimal/ToPlainStringTests.java Mon Sep 19 19:40:59 2011 -0700
195.3 @@ -1,5 +1,5 @@
195.4 /*
195.5 - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
195.6 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
195.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
195.8 *
195.9 * This code is free software; you can redistribute it and/or modify it
196.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
196.2 +++ b/test/java/net/Socket/ShutdownInput.java Mon Sep 19 19:40:59 2011 -0700
196.3 @@ -0,0 +1,89 @@
196.4 +/*
196.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
196.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
196.7 + *
196.8 + * This code is free software; you can redistribute it and/or modify it
196.9 + * under the terms of the GNU General Public License version 2 only, as
196.10 + * published by the Free Software Foundation.
196.11 + *
196.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
196.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
196.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
196.15 + * version 2 for more details (a copy is included in the LICENSE file that
196.16 + * accompanied this code).
196.17 + *
196.18 + * You should have received a copy of the GNU General Public License version
196.19 + * 2 along with this work; if not, write to the Free Software Foundation,
196.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
196.21 + *
196.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
196.23 + * or visit www.oracle.com if you need additional information or have any
196.24 + * questions.
196.25 + */
196.26 +
196.27 +/*
196.28 + * @test
196.29 + * @bug 7014860
196.30 + * @summary Socket.getInputStream().available() not clear for
196.31 + * case that connection is shutdown for reading
196.32 + */
196.33 +
196.34 +import java.io.InputStream;
196.35 +import java.io.OutputStream;
196.36 +import java.net.InetAddress;
196.37 +import java.net.InetSocketAddress;
196.38 +import java.net.ServerSocket;
196.39 +import java.net.Socket;
196.40 +import java.nio.channels.ServerSocketChannel;
196.41 +import java.nio.channels.SocketChannel;
196.42 +
196.43 +public class ShutdownInput {
196.44 + static boolean failed = false;
196.45 +
196.46 + public static void main(String args[]) throws Exception {
196.47 + InetAddress iaddr = InetAddress.getLocalHost();
196.48 +
196.49 + try ( ServerSocket ss = new ServerSocket(0);
196.50 + Socket s1 = new Socket(iaddr, ss.getLocalPort());
196.51 + Socket s2 = ss.accept() ) {
196.52 +
196.53 + test(s1, s2, "Testing NET");
196.54 + }
196.55 +
196.56 + // check the NIO socket adapter
196.57 + try (ServerSocketChannel sc = ServerSocketChannel.open().bind(null);
196.58 + SocketChannel s1 = SocketChannel.open(
196.59 + new InetSocketAddress(iaddr, sc.socket().getLocalPort()));
196.60 + SocketChannel s2 = sc.accept() ) {
196.61 +
196.62 + test(s1.socket(), s2.socket(), "Testing NIO");
196.63 + }
196.64 +
196.65 + if (failed) {
196.66 + throw new RuntimeException("Failed: check output");
196.67 + }
196.68 + }
196.69 +
196.70 + public static void test(Socket s1, Socket s2, String mesg) throws Exception {
196.71 + OutputStream os = s1.getOutputStream();
196.72 + os.write("This is a message".getBytes("US-ASCII"));
196.73 +
196.74 + InputStream in = s2.getInputStream();
196.75 + s2.shutdownInput();
196.76 +
196.77 + if (in.available() != 0) {
196.78 + failed = true;
196.79 + System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
196.80 + "but returns "+ in.available());
196.81 + }
196.82 +
196.83 + byte[] ba = new byte[2];
196.84 + if (in.read() != -1 ||
196.85 + in.read(ba) != -1 ||
196.86 + in.read(ba, 0, ba.length) != -1) {
196.87 +
196.88 + failed = true;
196.89 + System.out.append(mesg + ":" + s2 + " in.read() should be -1");
196.90 + }
196.91 + }
196.92 +}
197.1 --- a/test/java/net/URI/Test.java Thu Sep 15 18:53:28 2011 -0700
197.2 +++ b/test/java/net/URI/Test.java Mon Sep 19 19:40:59 2011 -0700
197.3 @@ -23,7 +23,7 @@
197.4
197.5 /* @test
197.6 * @summary Unit test for java.net.URI
197.7 - * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363
197.8 + * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363 7041800
197.9 * @author Mark Reinhold
197.10 */
197.11
197.12 @@ -1428,6 +1428,8 @@
197.13 gt(s, new URI("http://jag:CafeBabe@java.sun.com:94/b/c/d?q#f"));
197.14 lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?r#f"));
197.15 lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g"));
197.16 + eq(new URI("http://host/a%00bcd"), new URI("http://host/a%00bcd"));
197.17 + ne(new URI("http://host/a%00bcd"), new URI("http://host/aZ00bcd"));
197.18
197.19 lt("p", "s:p");
197.20 lt("s:p", "T:p");
198.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
198.2 +++ b/test/java/security/KeyPairGenerator/SolarisShortDSA.java Mon Sep 19 19:40:59 2011 -0700
198.3 @@ -0,0 +1,69 @@
198.4 +/*
198.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
198.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
198.7 + *
198.8 + * This code is free software; you can redistribute it and/or modify it
198.9 + * under the terms of the GNU General Public License version 2 only, as
198.10 + * published by the Free Software Foundation.
198.11 + *
198.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
198.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
198.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
198.15 + * version 2 for more details (a copy is included in the LICENSE file that
198.16 + * accompanied this code).
198.17 + *
198.18 + * You should have received a copy of the GNU General Public License version
198.19 + * 2 along with this work; if not, write to the Free Software Foundation,
198.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
198.21 + *
198.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
198.23 + * or visit www.oracle.com if you need additional information or have any
198.24 + * questions.
198.25 + */
198.26 +
198.27 +/*
198.28 + * @test
198.29 + * @bug 7081411
198.30 + * @summary DSA keypair generation affected by Solaris bug
198.31 + */
198.32 +
198.33 +import java.security.KeyPair;
198.34 +import java.security.KeyPairGenerator;
198.35 +import java.security.Signature;
198.36 +import sun.security.provider.DSAPrivateKey;
198.37 +
198.38 +public class SolarisShortDSA {
198.39 + static byte[] data = new byte[0];
198.40 + public static void main(String args[]) throws Exception {
198.41 + for (int i=0; i<10000; i++) {
198.42 + KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
198.43 + KeyPair kp = kpg.generateKeyPair();
198.44 + DSAPrivateKey dpk = (DSAPrivateKey)kp.getPrivate();
198.45 + int len = dpk.getX().bitLength();
198.46 + if (len <= 152) {
198.47 + if (!use(kp)) {
198.48 + String os = System.getProperty("os.name");
198.49 + // Solaris bug, update the following line once it's fixed
198.50 + if (os.equals("SunOS")) {
198.51 + throw new IllegalStateException(
198.52 + "Don't panic. This is a Solaris bug");
198.53 + } else {
198.54 + throw new RuntimeException("Real test failure");
198.55 + }
198.56 + }
198.57 + break;
198.58 + }
198.59 + }
198.60 + }
198.61 +
198.62 + static boolean use(KeyPair kp) throws Exception {
198.63 + Signature sig = Signature.getInstance("SHA1withDSA");
198.64 + sig.initSign(kp.getPrivate());
198.65 + sig.update(data);
198.66 + byte[] signed = sig.sign();
198.67 + Signature sig2 = Signature.getInstance("SHA1withDSA");
198.68 + sig2.initVerify(kp.getPublic());
198.69 + sig2.update(data);
198.70 + return sig2.verify(signed);
198.71 + }
198.72 +}
199.1 --- a/test/javax/xml/crypto/dsig/SecurityManager/XMLDSigWithSecMgr.java Thu Sep 15 18:53:28 2011 -0700
199.2 +++ b/test/javax/xml/crypto/dsig/SecurityManager/XMLDSigWithSecMgr.java Mon Sep 19 19:40:59 2011 -0700
199.3 @@ -26,6 +26,7 @@
199.4 * @bug 6436919 6460930
199.5 * @summary check that XML Signatures can be generated and validated with
199.6 * SecurityManager enabled and default policy
199.7 + * @run main/othervm XMLDSigWithSecMgr
199.8 * @author Sean Mullan
199.9 */
199.10 import java.io.*;
200.1 --- a/test/lib/security/java.policy/Ext_AllPolicy.sh Thu Sep 15 18:53:28 2011 -0700
200.2 +++ b/test/lib/security/java.policy/Ext_AllPolicy.sh Mon Sep 19 19:40:59 2011 -0700
200.3 @@ -54,19 +54,16 @@
200.4 NULL=/dev/null
200.5 PS=":"
200.6 FS="/"
200.7 - TMP=/tmp
200.8 ;;
200.9 CYGWIN* )
200.10 NULL=/dev/null
200.11 PS=";"
200.12 FS="/"
200.13 - TMP=/tmp
200.14 ;;
200.15 Windows_95 | Windows_98 | Windows_NT )
200.16 NULL=NUL
200.17 PS=";"
200.18 FS="\\"
200.19 - TMP="c:/temp"
200.20 ;;
200.21 * )
200.22 echo "Unrecognized system!"
201.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
201.2 +++ b/test/sun/security/krb5/auto/DupEtypes.java Mon Sep 19 19:40:59 2011 -0700
201.3 @@ -0,0 +1,63 @@
201.4 +/*
201.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
201.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
201.7 + *
201.8 + * This code is free software; you can redistribute it and/or modify it
201.9 + * under the terms of the GNU General Public License version 2 only, as
201.10 + * published by the Free Software Foundation.
201.11 + *
201.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
201.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
201.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
201.15 + * version 2 for more details (a copy is included in the LICENSE file that
201.16 + * accompanied this code).
201.17 + *
201.18 + * You should have received a copy of the GNU General Public License version
201.19 + * 2 along with this work; if not, write to the Free Software Foundation,
201.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201.21 + *
201.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201.23 + * or visit www.oracle.com if you need additional information or have any
201.24 + * questions.
201.25 + */
201.26 +
201.27 +/*
201.28 + * @test
201.29 + * @bug 7067974
201.30 + * @summary multiple ETYPE-INFO-ENTRY with same etype and different salt
201.31 + * @compile -XDignore.symbol.file DupEtypes.java
201.32 + * @run main/othervm DupEtypes 1
201.33 + * @run main/othervm DupEtypes 2
201.34 + * @run main/othervm/fail DupEtypes 3
201.35 + * @run main/othervm DupEtypes 4
201.36 + * @run main/othervm DupEtypes 5
201.37 + */
201.38 +
201.39 +import sun.security.jgss.GSSUtil;
201.40 +
201.41 +public class DupEtypes {
201.42 +
201.43 + public static void main(String[] args) throws Exception {
201.44 +
201.45 + OneKDC kdc = new OneKDC(null);
201.46 + kdc.writeJAASConf();
201.47 +
201.48 + // Different test cases, read KDC.processAsReq for details
201.49 + kdc.setOption(KDC.Option.DUP_ETYPE, Integer.parseInt(args[0]));
201.50 +
201.51 + Context c, s;
201.52 + c = Context.fromJAAS("client");
201.53 + s = Context.fromJAAS("server");
201.54 +
201.55 + c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
201.56 + s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
201.57 +
201.58 + Context.handshake(c, s);
201.59 +
201.60 + Context.transmit("i say high --", c, s);
201.61 + Context.transmit(" you say low", s, c);
201.62 +
201.63 + s.dispose();
201.64 + c.dispose();
201.65 + }
201.66 +}
202.1 --- a/test/sun/security/krb5/auto/KDC.java Thu Sep 15 18:53:28 2011 -0700
202.2 +++ b/test/sun/security/krb5/auto/KDC.java Mon Sep 19 19:40:59 2011 -0700
202.3 @@ -174,6 +174,10 @@
202.4 * Set all name-type to a value in response
202.5 */
202.6 RESP_NT,
202.7 + /**
202.8 + * Multiple ETYPE-INFO-ENTRY with same etype but different salt
202.9 + */
202.10 + DUP_ETYPE,
202.11 };
202.12
202.13 static {
202.14 @@ -881,48 +885,104 @@
202.15 bFlags[Krb5.TKT_OPTS_INITIAL] = true;
202.16
202.17 // Creating PA-DATA
202.18 - int[] epas = eTypes;
202.19 - if (options.containsKey(KDC.Option.RC4_FIRST_PREAUTH)) {
202.20 - for (int i=1; i<epas.length; i++) {
202.21 - if (epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC) {
202.22 - epas[i] = epas[0];
202.23 - epas[0] = EncryptedData.ETYPE_ARCFOUR_HMAC;
202.24 + DerValue[] pas2 = null, pas = null;
202.25 + if (options.containsKey(KDC.Option.DUP_ETYPE)) {
202.26 + int n = (Integer)options.get(KDC.Option.DUP_ETYPE);
202.27 + switch (n) {
202.28 + case 1: // customer's case in 7067974
202.29 + pas2 = new DerValue[] {
202.30 + new DerValue(new ETypeInfo2(1, null, null).asn1Encode()),
202.31 + new DerValue(new ETypeInfo2(1, "", null).asn1Encode()),
202.32 + new DerValue(new ETypeInfo2(1, OneKDC.REALM, new byte[]{1}).asn1Encode()),
202.33 + };
202.34 + pas = new DerValue[] {
202.35 + new DerValue(new ETypeInfo(1, null).asn1Encode()),
202.36 + new DerValue(new ETypeInfo(1, "").asn1Encode()),
202.37 + new DerValue(new ETypeInfo(1, OneKDC.REALM).asn1Encode()),
202.38 + };
202.39 + break;
202.40 + case 2: // we still reject non-null s2kparams and prefer E2 over E
202.41 + pas2 = new DerValue[] {
202.42 + new DerValue(new ETypeInfo2(1, OneKDC.REALM, new byte[]{1}).asn1Encode()),
202.43 + new DerValue(new ETypeInfo2(1, null, null).asn1Encode()),
202.44 + new DerValue(new ETypeInfo2(1, "", null).asn1Encode()),
202.45 + };
202.46 + pas = new DerValue[] {
202.47 + new DerValue(new ETypeInfo(1, OneKDC.REALM).asn1Encode()),
202.48 + new DerValue(new ETypeInfo(1, null).asn1Encode()),
202.49 + new DerValue(new ETypeInfo(1, "").asn1Encode()),
202.50 + };
202.51 + break;
202.52 + case 3: // but only E is wrong
202.53 + pas = new DerValue[] {
202.54 + new DerValue(new ETypeInfo(1, OneKDC.REALM).asn1Encode()),
202.55 + new DerValue(new ETypeInfo(1, null).asn1Encode()),
202.56 + new DerValue(new ETypeInfo(1, "").asn1Encode()),
202.57 + };
202.58 + break;
202.59 + case 4: // we also ignore rc4-hmac
202.60 + pas = new DerValue[] {
202.61 + new DerValue(new ETypeInfo(23, "ANYTHING").asn1Encode()),
202.62 + new DerValue(new ETypeInfo(1, null).asn1Encode()),
202.63 + new DerValue(new ETypeInfo(1, "").asn1Encode()),
202.64 + };
202.65 + break;
202.66 + case 5: // "" should be wrong, but we accept it now
202.67 + // See s.s.k.internal.PAData$SaltAndParams
202.68 + pas = new DerValue[] {
202.69 + new DerValue(new ETypeInfo(1, "").asn1Encode()),
202.70 + new DerValue(new ETypeInfo(1, null).asn1Encode()),
202.71 + };
202.72 + break;
202.73 + }
202.74 + } else {
202.75 + int[] epas = eTypes;
202.76 + if (options.containsKey(KDC.Option.RC4_FIRST_PREAUTH)) {
202.77 + for (int i=1; i<epas.length; i++) {
202.78 + if (epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC) {
202.79 + epas[i] = epas[0];
202.80 + epas[0] = EncryptedData.ETYPE_ARCFOUR_HMAC;
202.81 + break;
202.82 + }
202.83 + };
202.84 + } else if (options.containsKey(KDC.Option.ONLY_ONE_PREAUTH)) {
202.85 + epas = new int[] { eTypes[0] };
202.86 + }
202.87 + pas2 = new DerValue[epas.length];
202.88 + for (int i=0; i<epas.length; i++) {
202.89 + pas2[i] = new DerValue(new ETypeInfo2(
202.90 + epas[i],
202.91 + epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC ?
202.92 + null : getSalt(body.cname),
202.93 + null).asn1Encode());
202.94 + }
202.95 + boolean allOld = true;
202.96 + for (int i: eTypes) {
202.97 + if (i == EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96 ||
202.98 + i == EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96) {
202.99 + allOld = false;
202.100 break;
202.101 }
202.102 - };
202.103 - } else if (options.containsKey(KDC.Option.ONLY_ONE_PREAUTH)) {
202.104 - epas = new int[] { eTypes[0] };
202.105 + }
202.106 + if (allOld) {
202.107 + pas = new DerValue[epas.length];
202.108 + for (int i=0; i<epas.length; i++) {
202.109 + pas[i] = new DerValue(new ETypeInfo(
202.110 + epas[i],
202.111 + epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC ?
202.112 + null : getSalt(body.cname)
202.113 + ).asn1Encode());
202.114 + }
202.115 + }
202.116 }
202.117
202.118 - DerValue[] pas = new DerValue[epas.length];
202.119 - for (int i=0; i<epas.length; i++) {
202.120 - pas[i] = new DerValue(new ETypeInfo2(
202.121 - epas[i],
202.122 - epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC ?
202.123 - null : getSalt(body.cname),
202.124 - null).asn1Encode());
202.125 + DerOutputStream eid;
202.126 + if (pas2 != null) {
202.127 + eid = new DerOutputStream();
202.128 + eid.putSequence(pas2);
202.129 + outPAs.add(new PAData(Krb5.PA_ETYPE_INFO2, eid.toByteArray()));
202.130 }
202.131 - DerOutputStream eid = new DerOutputStream();
202.132 - eid.putSequence(pas);
202.133 -
202.134 - outPAs.add(new PAData(Krb5.PA_ETYPE_INFO2, eid.toByteArray()));
202.135 -
202.136 - boolean allOld = true;
202.137 - for (int i: eTypes) {
202.138 - if (i == EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96 ||
202.139 - i == EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96) {
202.140 - allOld = false;
202.141 - break;
202.142 - }
202.143 - }
202.144 - if (allOld) {
202.145 - for (int i=0; i<epas.length; i++) {
202.146 - pas[i] = new DerValue(new ETypeInfo(
202.147 - epas[i],
202.148 - epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC ?
202.149 - null : getSalt(body.cname)
202.150 - ).asn1Encode());
202.151 - }
202.152 + if (pas != null) {
202.153 eid = new DerOutputStream();
202.154 eid.putSequence(pas);
202.155 outPAs.add(new PAData(Krb5.PA_ETYPE_INFO, eid.toByteArray()));
203.1 --- a/test/sun/security/tools/jarsigner/AlgOptions.sh Thu Sep 15 18:53:28 2011 -0700
203.2 +++ b/test/sun/security/tools/jarsigner/AlgOptions.sh Mon Sep 19 19:40:59 2011 -0700
203.3 @@ -51,21 +51,18 @@
203.4 PS=":"
203.5 FS="/"
203.6 CP="${FS}bin${FS}cp -f"
203.7 - TMP=/tmp
203.8 ;;
203.9 CYGWIN* )
203.10 NULL=/dev/null
203.11 PS=";"
203.12 FS="/"
203.13 CP="cp -f"
203.14 - TMP=/tmp
203.15 ;;
203.16 Windows_* )
203.17 NULL=NUL
203.18 PS=";"
203.19 FS="\\"
203.20 CP="cp -f"
203.21 - TMP="c:/temp"
203.22 ;;
203.23 * )
203.24 echo "Unrecognized operating system!"
204.1 --- a/test/sun/security/tools/jarsigner/PercentSign.sh Thu Sep 15 18:53:28 2011 -0700
204.2 +++ b/test/sun/security/tools/jarsigner/PercentSign.sh Mon Sep 19 19:40:59 2011 -0700
204.3 @@ -51,21 +51,18 @@
204.4 PS=":"
204.5 FS="/"
204.6 CP="${FS}bin${FS}cp -f"
204.7 - TMP=/tmp
204.8 ;;
204.9 CYGWIN* )
204.10 NULL=/dev/null
204.11 PS=";"
204.12 FS="/"
204.13 CP="cp -f"
204.14 - TMP=/tmp
204.15 ;;
204.16 Windows_* )
204.17 NULL=NUL
204.18 PS=";"
204.19 FS="\\"
204.20 CP="cp -f"
204.21 - TMP="c:/temp"
204.22 ;;
204.23 * )
204.24 echo "Unrecognized operating system!"
205.1 --- a/test/sun/security/tools/jarsigner/diffend.sh Thu Sep 15 18:53:28 2011 -0700
205.2 +++ b/test/sun/security/tools/jarsigner/diffend.sh Mon Sep 19 19:40:59 2011 -0700
205.3 @@ -46,21 +46,18 @@
205.4 PS=":"
205.5 FS="/"
205.6 CP="${FS}bin${FS}cp -f"
205.7 - TMP=/tmp
205.8 ;;
205.9 CYGWIN* )
205.10 NULL=/dev/null
205.11 PS=";"
205.12 FS="/"
205.13 CP="cp -f"
205.14 - TMP=/tmp
205.15 ;;
205.16 Windows_* )
205.17 NULL=NUL
205.18 PS=";"
205.19 FS="\\"
205.20 CP="cp -f"
205.21 - TMP="c:/temp"
205.22 ;;
205.23 * )
205.24 echo "Unrecognized operating system!"
206.1 --- a/test/sun/security/tools/jarsigner/oldsig.sh Thu Sep 15 18:53:28 2011 -0700
206.2 +++ b/test/sun/security/tools/jarsigner/oldsig.sh Mon Sep 19 19:40:59 2011 -0700
206.3 @@ -47,21 +47,18 @@
206.4 PS=":"
206.5 FS="/"
206.6 CP="${FS}bin${FS}cp -f"
206.7 - TMP=/tmp
206.8 ;;
206.9 CYGWIN* )
206.10 NULL=/dev/null
206.11 PS=";"
206.12 FS="/"
206.13 CP="cp -f"
206.14 - TMP=/tmp
206.15 ;;
206.16 Windows_* )
206.17 NULL=NUL
206.18 PS=";"
206.19 FS="\\"
206.20 CP="cp -f"
206.21 - TMP="c:/temp"
206.22 ;;
206.23 * )
206.24 echo "Unrecognized operating system!"
207.1 --- a/test/sun/security/tools/keytool/AltProviderPath.sh Thu Sep 15 18:53:28 2011 -0700
207.2 +++ b/test/sun/security/tools/keytool/AltProviderPath.sh Mon Sep 19 19:40:59 2011 -0700
207.3 @@ -50,19 +50,16 @@
207.4 NULL=/dev/null
207.5 PS=":"
207.6 FS="/"
207.7 - TMP=/tmp
207.8 ;;
207.9 CYGWIN* )
207.10 NULL=/dev/null
207.11 PS=";"
207.12 FS="/"
207.13 - TMP=/tmp
207.14 ;;
207.15 Windows_* )
207.16 NULL=NUL
207.17 PS=";"
207.18 FS="\\"
207.19 - TMP="c:/temp"
207.20 ;;
207.21 * )
207.22 echo "Unrecognized operating system!"
208.1 --- a/test/sun/security/tools/keytool/SecretKeyKS.sh Thu Sep 15 18:53:28 2011 -0700
208.2 +++ b/test/sun/security/tools/keytool/SecretKeyKS.sh Mon Sep 19 19:40:59 2011 -0700
208.3 @@ -49,19 +49,16 @@
208.4 NULL=/dev/null
208.5 PS=":"
208.6 FS="/"
208.7 - TMP=/tmp
208.8 ;;
208.9 CYGWIN* )
208.10 NULL=/dev/null
208.11 PS=";"
208.12 FS="/"
208.13 - TMP=/tmp
208.14 ;;
208.15 Windows_* )
208.16 NULL=NUL
208.17 PS=";"
208.18 FS="\\"
208.19 - TMP="c:/temp"
208.20 ;;
208.21 * )
208.22 echo "Unrecognized operating system!"
209.1 --- a/test/sun/security/tools/keytool/StandardAlgName.sh Thu Sep 15 18:53:28 2011 -0700
209.2 +++ b/test/sun/security/tools/keytool/StandardAlgName.sh Mon Sep 19 19:40:59 2011 -0700
209.3 @@ -50,19 +50,16 @@
209.4 NULL=/dev/null
209.5 PS=":"
209.6 FS="/"
209.7 - TMP=/tmp
209.8 ;;
209.9 CYGWIN* )
209.10 NULL=/dev/null
209.11 PS=";"
209.12 FS="/"
209.13 - TMP=/tmp
209.14 ;;
209.15 Windows_* )
209.16 NULL=NUL
209.17 PS=";"
209.18 FS="\\"
209.19 - TMP="c:/temp"
209.20 ;;
209.21 * )
209.22 echo "Unrecognized operating system!"
210.1 --- a/test/sun/security/tools/keytool/i18n.sh Thu Sep 15 18:53:28 2011 -0700
210.2 +++ b/test/sun/security/tools/keytool/i18n.sh Mon Sep 19 19:40:59 2011 -0700
210.3 @@ -50,19 +50,16 @@
210.4 NULL=/dev/null
210.5 PS=":"
210.6 FS="/"
210.7 - TMP=/tmp
210.8 ;;
210.9 CYGWIN* )
210.10 NULL=/dev/null
210.11 PS=";"
210.12 FS="/"
210.13 - TMP=/tmp
210.14 ;;
210.15 Windows* )
210.16 NULL=NUL
210.17 PS=";"
210.18 FS="\\"
210.19 - TMP="c:/temp"
210.20 ;;
210.21 * )
210.22 echo "Unrecognized system!"
211.1 --- a/test/sun/security/tools/keytool/resource.sh Thu Sep 15 18:53:28 2011 -0700
211.2 +++ b/test/sun/security/tools/keytool/resource.sh Mon Sep 19 19:40:59 2011 -0700
211.3 @@ -46,17 +46,14 @@
211.4 SunOS | Linux )
211.5 NULL=/dev/null
211.6 FS="/"
211.7 - TMP=/tmp
211.8 ;;
211.9 CYGWIN* )
211.10 NULL=/dev/null
211.11 FS="/"
211.12 - TMP=/tmp
211.13 ;;
211.14 Windows_* )
211.15 NULL=NUL
211.16 FS="\\"
211.17 - TMP="c:/temp"
211.18 ;;
211.19 * )
211.20 echo "Unrecognized operating system!"
211.21 @@ -65,13 +62,11 @@
211.22 esac
211.23
211.24 # the test code
211.25 -${TESTJAVA}${FS}bin${FS}keytool > ${TMP}${FS}temp_file_40875602475 2> ${NULL}
211.26 -grep MissingResourceException ${TMP}${FS}temp_file_40875602475
211.27 +${TESTJAVA}${FS}bin${FS}keytool > temp_file_40875602475 2> ${NULL}
211.28 +grep MissingResourceException temp_file_40875602475
211.29
211.30 if [ $? -eq 0 ]; then
211.31 - rm ${TMP}${FS}temp_file_40875602475
211.32 exit 1
211.33 fi
211.34
211.35 -rm ${TMP}${FS}temp_file_40875602475
211.36 exit 0
212.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
212.2 +++ b/test/sun/security/tools/keytool/trystore.sh Mon Sep 19 19:40:59 2011 -0700
212.3 @@ -0,0 +1,65 @@
212.4 +#
212.5 +# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
212.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
212.7 +#
212.8 +# This code is free software; you can redistribute it and/or modify it
212.9 +# under the terms of the GNU General Public License version 2 only, as
212.10 +# published by the Free Software Foundation.
212.11 +#
212.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
212.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
212.14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
212.15 +# version 2 for more details (a copy is included in the LICENSE file that
212.16 +# accompanied this code).
212.17 +#
212.18 +# You should have received a copy of the GNU General Public License version
212.19 +# 2 along with this work; if not, write to the Free Software Foundation,
212.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
212.21 +#
212.22 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
212.23 +# or visit www.oracle.com if you need additional information or have any
212.24 +# questions.
212.25 +#
212.26 +
212.27 +# @test
212.28 +# @bug 7047200
212.29 +# @summary keytool can try save to a byte array before overwrite the file
212.30 +
212.31 +if [ "${TESTJAVA}" = "" ] ; then
212.32 + JAVAC_CMD=`which javac`
212.33 + TESTJAVA=`dirname $JAVAC_CMD`/..
212.34 +fi
212.35 +
212.36 +# set platform-dependent variables
212.37 +OS=`uname -s`
212.38 +case "$OS" in
212.39 + Windows_* )
212.40 + FS="\\"
212.41 + ;;
212.42 + * )
212.43 + FS="/"
212.44 + ;;
212.45 +esac
212.46 +
212.47 +rm trystore.jks 2> /dev/null
212.48 +
212.49 +KEYTOOL="${TESTJAVA}${FS}bin${FS}keytool -storetype jks -keystore trystore.jks"
212.50 +$KEYTOOL -genkeypair -alias a -dname CN=A -storepass changeit -keypass changeit
212.51 +$KEYTOOL -genkeypair -alias b -dname CN=B -storepass changeit -keypass changeit
212.52 +
212.53 +# We use -protected for JKS keystore. This is illegal so the command should
212.54 +# fail. Then we can check if the keystore is damaged.
212.55 +
212.56 +$KEYTOOL -genkeypair -protected -alias b -delete -debug
212.57 +
212.58 +if [ $? = 0 ]; then
212.59 + echo "What? -protected works for JKS?"
212.60 + exit 1
212.61 +fi
212.62 +
212.63 +$KEYTOOL -list -storepass changeit
212.64 +
212.65 +if [ $? != 0 ]; then
212.66 + echo "Keystore file damaged"
212.67 + exit 2
212.68 +fi
213.1 --- a/test/sun/security/tools/policytool/Alias.sh Thu Sep 15 18:53:28 2011 -0700
213.2 +++ b/test/sun/security/tools/policytool/Alias.sh Mon Sep 19 19:40:59 2011 -0700
213.3 @@ -51,13 +51,11 @@
213.4 NULL=/dev/null
213.5 PS=":"
213.6 FS="/"
213.7 - TMP=/tmp
213.8 ;;
213.9 Windows* )
213.10 NULL=NUL
213.11 PS=";"
213.12 FS="\\"
213.13 - TMP="c:/temp"
213.14 ;;
213.15 * )
213.16 echo "Unrecognized system!"
214.1 --- a/test/sun/security/tools/policytool/ChangeUI.sh Thu Sep 15 18:53:28 2011 -0700
214.2 +++ b/test/sun/security/tools/policytool/ChangeUI.sh Mon Sep 19 19:40:59 2011 -0700
214.3 @@ -50,13 +50,11 @@
214.4 NULL=/dev/null
214.5 PS=":"
214.6 FS="/"
214.7 - TMP=/tmp
214.8 ;;
214.9 Windows* )
214.10 NULL=NUL
214.11 PS=";"
214.12 FS="\\"
214.13 - TMP="c:/temp"
214.14 ;;
214.15 * )
214.16 echo "Unrecognized system!"
215.1 --- a/test/sun/security/tools/policytool/OpenPolicy.sh Thu Sep 15 18:53:28 2011 -0700
215.2 +++ b/test/sun/security/tools/policytool/OpenPolicy.sh Mon Sep 19 19:40:59 2011 -0700
215.3 @@ -50,13 +50,11 @@
215.4 NULL=/dev/null
215.5 PS=":"
215.6 FS="/"
215.7 - TMP=/tmp
215.8 ;;
215.9 Windows* )
215.10 NULL=NUL
215.11 PS=";"
215.12 FS="\\"
215.13 - TMP="c:/temp"
215.14 ;;
215.15 * )
215.16 echo "Unrecognized system!"
216.1 --- a/test/sun/security/tools/policytool/SaveAs.sh Thu Sep 15 18:53:28 2011 -0700
216.2 +++ b/test/sun/security/tools/policytool/SaveAs.sh Mon Sep 19 19:40:59 2011 -0700
216.3 @@ -51,13 +51,11 @@
216.4 NULL=/dev/null
216.5 PS=":"
216.6 FS="/"
216.7 - TMP=/tmp
216.8 ;;
216.9 Windows* )
216.10 NULL=NUL
216.11 PS=";"
216.12 FS="\\"
216.13 - TMP="c:/temp"
216.14 ;;
216.15 * )
216.16 echo "Unrecognized system!"
217.1 --- a/test/sun/security/tools/policytool/UpdatePermissions.sh Thu Sep 15 18:53:28 2011 -0700
217.2 +++ b/test/sun/security/tools/policytool/UpdatePermissions.sh Mon Sep 19 19:40:59 2011 -0700
217.3 @@ -50,13 +50,11 @@
217.4 NULL=/dev/null
217.5 PS=":"
217.6 FS="/"
217.7 - TMP=/tmp
217.8 ;;
217.9 Windows* )
217.10 NULL=NUL
217.11 PS=";"
217.12 FS="\\"
217.13 - TMP="c:/temp"
217.14 ;;
217.15 * )
217.16 echo "Unrecognized system!"
218.1 --- a/test/sun/security/tools/policytool/UsePolicy.sh Thu Sep 15 18:53:28 2011 -0700
218.2 +++ b/test/sun/security/tools/policytool/UsePolicy.sh Mon Sep 19 19:40:59 2011 -0700
218.3 @@ -50,13 +50,11 @@
218.4 NULL=/dev/null
218.5 PS=":"
218.6 FS="/"
218.7 - TMP=/tmp
218.8 ;;
218.9 Windows* )
218.10 NULL=NUL
218.11 PS=";"
218.12 FS="\\"
218.13 - TMP="c:/temp"
218.14 ;;
218.15 * )
218.16 echo "Unrecognized system!"
219.1 --- a/test/sun/security/tools/policytool/i18n.sh Thu Sep 15 18:53:28 2011 -0700
219.2 +++ b/test/sun/security/tools/policytool/i18n.sh Mon Sep 19 19:40:59 2011 -0700
219.3 @@ -50,13 +50,11 @@
219.4 NULL=/dev/null
219.5 PS=":"
219.6 FS="/"
219.7 - TMP=/tmp
219.8 ;;
219.9 Windows* )
219.10 NULL=NUL
219.11 PS=";"
219.12 FS="\\"
219.13 - TMP="c:/temp"
219.14 ;;
219.15 * )
219.16 echo "Unrecognized system!"