glassfish
  1. glassfish
  2. GLASSFISH-21585

The list of JVM options is lost empty when an invalid option is added.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.1, 5.0
    • Fix Version/s: None
    • Component/s: admin, rest-interface
    • Labels:
      None

      Description

      When an invalid JVM option is added in "JVM Options" page, all JVM Options are removed.
      The impact of this bug is high as it is impossible to restore all the settings.

      Follow the steps below to reproduce this bug.

      Steps to reproduce:
      1. Open "Configurations>server-config>JVM Settings" from the Navigation tree.
      2. Open "JVM Options" tab.
      3. Add a new JVM option which does not start with -(dash). For example abc=def.
      4. Click "Save" button. Then, error message is displayed at the top of page.
      5. Go to another page and re-open this "JVM Options" page to reload the data.
      6. All JVM options are deleted.

      Cause:
      I found the problem is in CollectionLeafResource.java. In "create" method of CollectionLeafResource.java, the JVM options are updated with the following procedure.
      1. Check if the JVM options have been changed.
      2. If yes, delete all the JVM options.
      3. Create all the JVM options including added/changed option.
      If step 3 is failed with error for some reasons, then all JVM options are deleted as a result. There is no recovery of the JVM options after 3 is executed.

      Suggested Fix:
      Add Step 4 to the above and recover the existing JVM options. The new procedure is as follows:
      1. Check if the JVM options have been changed.
      2. If yes, backup all the JVM options. Then, delete all the JVM options.
      3. Create all the JVM options.
      4. If step 3 is failed with error, restore all the JVM options.

      The following is the patch for Glassfish 4.1.1

      nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/resources/CollectionLeafResource.java

      
      Index: CollectionLeafResource.java
      ===================================================================
      --- CollectionLeafResource.java	(revision 64342)
      +++ CollectionLeafResource.java	(working copy)
      @@ -140,9 +140,12 @@
       
               String postCommand = getPostCommand();
               Map<String, String> payload = null;
      +        Map<String, String> existing = null;
       
               if (isJvmOptions(postCommand)) {
                   deleteExistingOptions();
      +            // All JVM options are deleted. Store existing JVM options in existing. 
      +            existing = deleteExistingOptions();
                   payload = processData(data);
               } else {
                   payload = data;
      @@ -149,8 +152,16 @@
               }
       
       
      -        return runCommand(postCommand, payload, "rest.resource.create.message",
      +        // Create all JVM options.
      +        Response response = runCommand(postCommand, payload, "rest.resource.create.message",
                   "\"{0}\" created successfully.", "rest.resource.post.forbidden","POST on \"{0}\" is forbidden.");
      +        if (response.getStatus() != 200) {
      +            // If creating JVM options is error, restore JVM options with exsiting.  
      +            payload = processData(existing);
      +            runCommand(postCommand, payload, "rest.resource.create.message",
      +                "\"{0}\" created successfully.", "rest.resource.post.forbidden","POST on \"{0}\" is forbidden.");
      +        }
      +        return response;
           }
       
           @PUT //create
      @@ -362,7 +373,7 @@
               return (command != null) && (command.contains("jvm-options"));
           }
       
      -    protected void deleteExistingOptions() {
      +    protected Map<String, String> deleteExistingOptions() {
               Map<String, String> existing = new HashMap<String, String>();
               existing.put("target", target);
               for (String option : getEntity()) {
      @@ -379,6 +390,7 @@
                       "\"{0}\" deleted successfully.",
                       "rest.resource.delete.forbidden",
                       "DELETE on \"{0}\" is forbidden.");
      +        return existing;
           }
       
       }
       
      

        Activity

        Hide
        Kokil_Jain added a comment -

        Fixed by r64414

        Show
        Kokil_Jain added a comment - Fixed by r64414

          People

          • Assignee:
            Kokil_Jain
            Reporter:
            tak09
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: