Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8246802

javac fails to report error on single argument and single arbitrary arguments

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 11, 15
    • Fix Version/s: None
    • Component/s: tools

      Description

      ADDITIONAL SYSTEM INFORMATION :
      AMD Ryzen 5 3550H
      8GB SODIMM
      Windows 10 64-bit Insider Fast 19640.1
      Java Early Adopter 15+26


      A DESCRIPTION OF THE PROBLEM :
      Java Compiler executes single argument (String) over single argument in continued array argument (String...)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Two overloaded functions, one with a single argument (eg. String) and other with arbitrary arguments (eg. String...). On invocation of the method by a single argument(eg. func("Hello")), the former function is invoked. However on commenting the first (single argument) function, java executes the latter function. On testing it is found that javac does not throw an error instead.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Syntax Error by the compiler on unable to distingush between single (test(String)) and continued (test(String...)) arguments
      ACTUAL -
      2)Hello

      ---------- BEGIN SOURCE ----------
      public class Main {

      public static void main(String[] args) {
      test("Hello");
      }

      public static void test(String... arr) {
      for(String s:arr) {
      System.out.println("1)"+s);
      }

      }

      public static void test(String st) {
      System.out.println("2)"+st);
      }

      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: