Launching single file source code program - "error: class found on application class path"

Jaikiran Pai jai.forums2013 at gmail.com
Tue Jun 19 00:43:40 UTC 2018


Hi Jonathan,

If this is intentional and if there's no plan to change this behaviour, 
would it be possible to make that error message a bit more 
clear/verbose. The first few times when I kept seeing:

"error: class found on application class path: A"

I kept reading it as "class *not* found" (given the numerous occasions 
I'm used to seeing class not found exceptions in logs). Furthermore, the 
message in its current form, at least to me, feels more like a debug log 
than an error notification. Would it be possible to change it to 
something along the lines of:

"error: A compiled class <fully qualified class name> already exists on 
the application classpath and as a result the same class cannot be used 
as a source for launching single-file source code program".

As for the reason why this is intentionally marked as an error, is it 
because the execution of the auto-compiled source file can no longer be 
guaranteed to pick up the "right" class file if there's more than one 
instance of the fully qualified classname in the application classpath? 
At this point, I'm just curious about the reasoning and not really 
asking for this to be supported. I can understand that, since this is a 
source file that the user is executing and since they will have access 
to it and furthermore, since it's just going to be one single file, it's 
reasonable to expect the user to edit the file to use a different 
classname, if at all they run into such issues due to the content of 
their application classpath.

-Jaikiran


On 19/06/18 3:12 AM, Jonathan Gibbons wrote:
>
>
> On 6/18/18 2:33 PM, Attila Szegedi wrote:
>> On 2018. Jun 18., at 19:52, Jonathan Gibbons 
>> <jonathan.gibbons at oracle.com> wrote:
>>> On 06/17/2018 03:56 AM, Jaikiran Pai wrote:
>>>> […]
>>>>
>>>> The /tmp/foo-bar directory now consists of A.class and A.java. I 
>>>> then went ahead and (tried) to launch the A.java using the new 
>>>> feature as previously:
>>>>
>>>>> java A.java
>>>> I now get this error message:
>>>>
>>>> error: class found on application class path: A
>>>> […]
>>>> 2. Why is this an error? Is it intentional?
>>> This is the intended behavior, to avoid the ambiguity of having the 
>>> class on the classpath (which defaults to the current directory) and 
>>> the internally-compiled class generated from the source file.
>> Is this really ambiguous?
>>
>> If the user runs “java A.java”, their intent is clearly to run the 
>> source code file. The file name is explicitly spelt out in the command.
>>
>> If the user runs "java A”, then – if only from a purely 
>> backwards-compatible perspective – it should run the precompiled 
>> class; same way “java” command worked before this feature existed. I 
>> can see how one might argue user's intent was ambiguous in this case, 
>> though. (But then, it isn't the case original poster asked about.)
>>
>> Attila.
>>
>
> Yes, we wanted to avoid any confusion between the possibility of the 
> class being on the classpath and being specified as a source file.
>
> -- Jon



More information about the jdk-dev mailing list