Index: applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/OpeningTimeUtils.java
===================================================================
--- applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/OpeningTimeUtils.java	(revision 30116)
+++ applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/OpeningTimeUtils.java	(revision 30117)
@@ -113,6 +113,5 @@
      */
     public static String makeStringFromRects(ArrayList<TimeRect> givenTimeRects) {
-        // create an array of booleans representing every minute on all the days
-        // in a week
+        // create an array of booleans representing every minute on all the days in a week
         boolean[][] minuteArray = new boolean[7][24 * 60 + 2];
         for (int day = 0; day < 7; ++day) {
@@ -259,3 +258,27 @@
         return ret;
     }
+    
+    /**
+     * Ensures the given day is comprised between 0 and 6.
+     * @param day The day to check
+     * @param paramName The parameter name, used in error message
+     * @throws IllegalArgumentException if the day is invalid
+     */
+    public static final void ensureValidDay(int day, String paramName) throws IllegalArgumentException {
+        if (day < 0 || day > 6) {
+            throw new IllegalArgumentException(paramName + " is not a valid day (0-6). Given value is " + day);
+        }
+    }
+
+    /**
+     * Ensures the given minute is comprised between 0 and 24*60+1.
+     * @param minute The minute to check
+     * @param paramName The parameter name, used in error message
+     * @throws IllegalArgumentException if the minute is invalid
+     */
+    public static final void ensureValidMinute(int minute, String paramName) throws IllegalArgumentException {
+        if (minute < 0 || minute > 24*60+1) {
+            throw new IllegalArgumentException(paramName + " is not a valid minute (0-1441). Given value is " + minute);
+        }
+    }
 }
Index: applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/OheEditor.java
===================================================================
--- applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/OheEditor.java	(revision 30116)
+++ applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/OheEditor.java	(revision 30117)
@@ -176,5 +176,7 @@
     }
 
-    // update all the TimeRects with new Data
+    /**
+     * Updates all the TimeRects with new data.
+     */
     public void initTimeRects() {
         contentPanel.removeAll();
Index: applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/TimeRect.java
===================================================================
--- applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/TimeRect.java	(revision 30116)
+++ applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/TimeRect.java	(revision 30117)
@@ -19,4 +19,6 @@
 import javax.swing.JPopupMenu;
 
+import org.openstreetmap.josm.plugins.ohe.OpeningTimeUtils;
+
 public class TimeRect extends JPanel implements MouseListener, MouseMotionListener {
     
@@ -54,6 +56,10 @@
 
     public TimeRect(OheEditor editor, int dayStart, int dayEnd, int minutesStart, int minutesEnd) {
+        OpeningTimeUtils.ensureValidDay(dayStart, "dayStart");
+        OpeningTimeUtils.ensureValidDay(dayEnd, "dayEnd");
+        OpeningTimeUtils.ensureValidMinute(minutesStart, "minutesStart");
+        OpeningTimeUtils.ensureValidMinute(minutesEnd, "minutesEnd");
+        
         this.editor = editor;
-
         this.dayStart = dayStart;
         this.dayEnd = dayEnd;
@@ -69,8 +75,16 @@
     }
 
+    /**
+     * Returns the starting day, as an index between 0 and 6.
+     * @return the starting day index
+     */
     public int getDayStart() {
         return dayStart;
     }
 
+    /**
+     * Returns the ending day, as an index between 0 and 6.
+     * @return the ending day index
+     */
     public int getDayEnd() {
         return dayEnd;
@@ -86,6 +100,5 @@
 
     public void reposition() {
-        setBounds(editor.getPanelBoundsForTimeinterval(dayStart, dayEnd + 1,
-                minuteStart, minuteEnd));
+        setBounds(editor.getPanelBoundsForTimeinterval(dayStart, dayEnd + 1, minuteStart, minuteEnd));
         editor.contentPanel.repaint();
     }
@@ -99,6 +112,10 @@
     }
 
-    private void updateTimeInterval(int newDayStart, int newDayEnd,
-            int newMinuteStart, int newMinuteEnd) {
+    private void updateTimeInterval(int newDayStart, int newDayEnd, int newMinuteStart, int newMinuteEnd) {
+        OpeningTimeUtils.ensureValidDay(newDayStart, "newDayStart");
+        OpeningTimeUtils.ensureValidDay(newDayEnd, "newDayEnd");
+        OpeningTimeUtils.ensureValidMinute(newMinuteStart, "newMinuteStart");
+        OpeningTimeUtils.ensureValidMinute(newMinuteEnd, "newMinuteEnd");
+
         dayStart = newDayStart;
         dayEnd = newDayEnd;
@@ -185,6 +202,5 @@
     public void showMenu(MouseEvent evt) {
         JPopupMenu menu = new JPopupMenu();
-        final JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem(
-                tr("open end"), isOpenEndInterval());
+        final JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem(tr("open end"), isOpenEndInterval());
         menu.add(cbMenuItem);
         cbMenuItem.addActionListener(new ActionListener() {
@@ -192,6 +208,5 @@
             public void actionPerformed(ActionEvent e) {
                 if (cbMenuItem.isSelected())
-                    updateTimeInterval(dayStart, dayEnd, minuteStart,
-                            24 * 60 + 1);
+                    updateTimeInterval(dayStart, dayEnd, minuteStart, 24 * 60 + 1);
                 else
                     updateTimeInterval(dayStart, dayEnd, minuteStart, 24 * 60);
@@ -265,6 +280,5 @@
                 } else if (newDayStart >= 0 && newDayEnd <= 6) {
                     actualDayDrag += xDiff;
-                    updateTimeInterval(newDayStart, newDayEnd, minuteStart,
-                            minuteEnd);
+                    updateTimeInterval(newDayStart, newDayEnd, minuteStart, minuteEnd);
                 }
             }
@@ -282,6 +296,5 @@
                         && (newMinutesEnd <= 24 * 60 || isOpenEndInterval())) {
                     actualMinuteDrag += yDiff;
-                    updateTimeInterval(dayStart, dayEnd, newMinutesStart,
-                            newMinutesEnd);
+                    updateTimeInterval(dayStart, dayEnd, newMinutesStart, newMinutesEnd);
                 }
             }
