diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java
index bec3faacbfd8224baa89587590dfcc4ec7d99412..9d037c1e670af601dc8ecdbb02c09c173f6c69a8 100644
--- a/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java
+++ b/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java
@@ -1560,6 +1560,10 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
* location that one might place a caret. Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
+ * This method enables specifying a position to convert
+ * within the range of >=0. If the value is -1, a position
+ * will be calculated automatically. If the value < -1,
+ * the {@code BadLocationException} will be thrown.
*
* @param pos the position to convert >= 0
* @param a the allocated region to render into
@@ -1569,13 +1573,17 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
* SwingConstants.NORTH, or SwingConstants.SOUTH.
* @return the location within the model that best represents the next
* location visual position.
- * @exception BadLocationException
+ * @exception BadLocationException the given position is not a valid
+ * position within the document
* @exception IllegalArgumentException for an invalid direction
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
int direction,
Position.Bias[] biasRet)
throws BadLocationException {
+ if (pos < -1) {
+ throw new BadLocationException("invalid position", pos);
+ }
if( view != null ) {
int nextPos = view.getNextVisualPositionFrom(pos, b, a,
direction, biasRet);
diff --git a/src/share/classes/javax/swing/text/AsyncBoxView.java b/src/share/classes/javax/swing/text/AsyncBoxView.java
index 7440eee2a26398b38890ece610e1f3d32cf15009..63ed6ffc525a919cd20fee0db05e04b2397b9fbd 100644
--- a/src/share/classes/javax/swing/text/AsyncBoxView.java
+++ b/src/share/classes/javax/swing/text/AsyncBoxView.java
@@ -827,8 +827,12 @@ public class AsyncBoxView extends View {
* location that one might place a caret. Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
+ * This method enables specifying a position to convert
+ * within the range of >=0. If the value is -1, a position
+ * will be calculated automatically. If the value < -1,
+ * the {@code BadLocationException} will be thrown.
*
- * @param pos the position to convert >= 0
+ * @param pos the position to convert
* @param a the allocated region to render into
* @param direction the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard;
@@ -842,13 +846,17 @@ public class AsyncBoxView extends View {
* @param biasRet an array contain the bias that was checked
* @return the location within the model that best represents the next
* location visual position
- * @exception BadLocationException
+ * @exception BadLocationException the given position is not a valid
+ * position within the document
* @exception IllegalArgumentException if direction is invalid
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
int direction,
Position.Bias[] biasRet)
throws BadLocationException {
+ if (pos < -1) {
+ throw new BadLocationException("invalid position", pos);
+ }
return Utilities.getNextVisualPositionFrom(
this, pos, b, a, direction, biasRet);
}
diff --git a/src/share/classes/javax/swing/text/CompositeView.java b/src/share/classes/javax/swing/text/CompositeView.java
index 0af70dd335a347e9b6637ec9226d6e20c643a969..6d57c638bb9e42844e18c542fbf70d94bb26f369 100644
--- a/src/share/classes/javax/swing/text/CompositeView.java
+++ b/src/share/classes/javax/swing/text/CompositeView.java
@@ -435,8 +435,12 @@ public abstract class CompositeView extends View {
* might not allow access to some of the locations in the model.
* This is a convenience method for {@link #getNextNorthSouthVisualPositionFrom}
* and {@link #getNextEastWestVisualPositionFrom}.
+ * This method enables specifying a position to convert
+ * within the range of >=0. If the value is -1, a position
+ * will be calculated automatically. If the value < -1,
+ * the {@code BadLocationException} will be thrown.
*
- * @param pos the position to convert >= 0
+ * @param pos the position to convert
* @param b a bias value of either Position.Bias.Forward
* or Position.Bias.Backward
* @param a the allocated region to render into
@@ -452,12 +456,16 @@ public abstract class CompositeView extends View {
* @param biasRet an array containing the bias that was checked
* @return the location within the model that best represents the next
* location visual position
- * @exception BadLocationException
+ * @exception BadLocationException the given position is not a valid
+ * position within the document
* @exception IllegalArgumentException if direction is invalid
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
int direction, Position.Bias[] biasRet)
throws BadLocationException {
+ if (pos < -1) {
+ throw new BadLocationException("invalid position", pos);
+ }
Rectangle alloc = getInsideAllocation(a);
switch (direction) {
diff --git a/src/share/classes/javax/swing/text/GlyphView.java b/src/share/classes/javax/swing/text/GlyphView.java
index 0c801cfc04ac060487ebce1a100ea18451fccfec..6aef3682392e8cafb27a84012eb81efecff5518f 100644
--- a/src/share/classes/javax/swing/text/GlyphView.java
+++ b/src/share/classes/javax/swing/text/GlyphView.java
@@ -879,8 +879,12 @@ public class GlyphView extends View implements TabableView, Cloneable {
* visible, they might not be in the same order found in the model, or
* they just might not allow access to some of the locations in the
* model.
+ * This method enables specifying a position to convert
+ * within the range of >=0. If the value is -1, a position
+ * will be calculated automatically. If the value < -1,
+ * the {@code BadLocationException} will be thrown.
*
- * @param pos the position to convert >= 0
+ * @param pos the position to convert
* @param a the allocated region to render into
* @param direction the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard.
@@ -888,7 +892,8 @@ public class GlyphView extends View implements TabableView, Cloneable {
* SwingConstants.NORTH, or SwingConstants.SOUTH.
* @return the location within the model that best represents the next
* location visual position.
- * @exception BadLocationException
+ * @exception BadLocationException the given position is not a valid
+ * position within the document
* @exception IllegalArgumentException for an invalid direction
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
@@ -896,6 +901,9 @@ public class GlyphView extends View implements TabableView, Cloneable {
Position.Bias[] biasRet)
throws BadLocationException {
+ if (pos < -1) {
+ throw new BadLocationException("invalid position", pos);
+ }
return painter.getNextVisualPositionFrom(this, pos, b, a, direction, biasRet);
}
diff --git a/src/share/classes/javax/swing/text/View.java b/src/share/classes/javax/swing/text/View.java
index 1bd35207094cabd955242475e534b678ff777b93..e4e0a5147dff9edf1da57e2d9975e3d7ee13bd5e 100644
--- a/src/share/classes/javax/swing/text/View.java
+++ b/src/share/classes/javax/swing/text/View.java
@@ -476,8 +476,12 @@ public abstract class View implements SwingConstants {
* Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
+ * This method enables specifying a position to convert
+ * within the range of >=0. If the value is -1, a position
+ * will be calculated automatically. If the value < -1,
+ * the {@code BadLocationException} will be thrown.
*
- * @param pos the position to convert >= 0
+ * @param pos the position to convert
* @param a the allocated region in which to render
* @param direction the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard.
@@ -490,7 +494,8 @@ public abstract class View implements SwingConstants {
*
* @return the location within the model that best represents the next
* location visual position
- * @exception BadLocationException
+ * @exception BadLocationException the given position is not a valid
+ * position within the document
* @exception IllegalArgumentException if direction
* doesn't have one of the legal values above
*/