GEdit opens java files with C source highlighting

Bug #64869 reported by Ryan Zeigler
6
Affects Status Importance Assigned to Milestone
shared-mime
Fix Released
Medium
shared-mime-info (Ubuntu)
Fix Released
Low
Ubuntu Desktop Bugs

Bug Description

Binary package hint: gedit

In edgy, gedit opens up java files with C highlighting. This occurs for every file with the .java extension I have opened.

Revision history for this message
John Vivirito (gnomefreak) wrote :

Did you set it to no highlighting? if you go to view>highlight mode> none it should than not highlight any file that you open.

Changed in gedit:
status: Unconfirmed → Needs Info
Revision history for this message
Ryan Zeigler (rzeigler) wrote :

I'm not sure what you mean. Previously when a java file was opened it was highlighted for java. Now, when I open a java file it is stuck with C highlighting which means that words like public and class are not highlighted, but types that are part of c like int are.

Revision history for this message
Sebastien Bacher (seb128) wrote :

If you right click on a .java from nautilus, open the properties, what mimetype is listed? if you go to the gedit preferences, what highlighting type is selected?

Changed in gedit:
assignee: nobody → desktop-bugs
Revision history for this message
Ryan Zeigler (rzeigler) wrote :

text/x-csrc

Apologies for not checking that first :-(

Revision history for this message
John Vivirito (gnomefreak) wrote :

This was a wrong settings issue not a bug. Thank you for reporting this bug and feel free to report any more that you find.

Changed in gedit:
status: Needs Info → Rejected
Revision history for this message
Sebastien Bacher (seb128) wrote :

John, don't close bugs too fast. Having a .java detected as text/x-csrc is a bug. Could you attach an example of such file to the bug?

Revision history for this message
Ryan Zeigler (rzeigler) wrote :
Revision history for this message
Sebastien Bacher (seb128) wrote :

shared-mime-info defines files starting by "/*" as a C source file. If you add an blank char before it it's detected as a java file. Is "/*" a regular java comment?

Changed in gedit:
importance: Undecided → Low
status: Rejected → Confirmed
Revision history for this message
Ryan Zeigler (rzeigler) wrote :

/* ... */ is what I was taught to use a Java comment by Professors. Furthermore, when I open the file on my Dapper box in nautilus, the mime-type is
text/x-java

Revision history for this message
zizou (spamit) wrote :

I stumbled upon this issue after upgrading from Ubuntu 6.06 to 6.10.

The following "patch" worked for me:

1. Open the file Override.xml (create it when missing)

On console:
gedit ~/.local/share/mime/packages/Override.xml

2. Make the file look the following (but don't remove other possible entries you might have):

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-javascript">
    <sub-class-of type="text/plain"/>
    <comment>Javascript program</comment>
    <glob pattern="*.js"/>
    <magic priority="30">
      <match value="/*" type="string" offset="0"/>
      <match value="//" type="string" offset="0"/>
    </magic>
  </mime-type>
</mime-info>

3. Rebuild the mime-type database. The changes should be instant-applied, but if not try logging out and logging back in.

On console:
update-mime-database ~/.local/share/mime

Revision history for this message
In , Sebastian Dröge (slomo) wrote :

Hi,
current shared-mime-info detects Java source code as C source code if it starts
with a /* ... */ or // comment. Attached patch fixes this.

Bye

Revision history for this message
In , Sebastian Dröge (slomo) wrote :

Created an attachment (id=8180)
java-parentclass.patch

Sebastian Dröge (slomo)
Changed in shared-mime:
status: Unconfirmed → Unknown
Revision history for this message
Sebastian Dröge (slomo) wrote :

Should be fixed in feisty with shared-mime-info 0.19-1ubuntu3 now.

Changed in shared-mime-info:
status: Confirmed → Fix Released
Changed in shared-mime:
status: Unknown → Confirmed
Revision history for this message
In , Bastien Nocera (hadess-deactivatedaccount) wrote :

2007-02-05 Bastien Nocera <email address hidden>

        * freedesktop.org.xml.in: Patch from Sebastian Dröge <email address hidden>
        to not mis-detect Java files as C when they start with comments
        (Closes: #9407), same trick with CSS files (Closes: #9469)

Changed in shared-mime:
status: Confirmed → Fix Released
Revision history for this message
Savvas Radevic (medigeek) wrote :

Someone mentioned that this might have reappeared for Ubuntu hardy heron 8.04
http://ubuntuforums.org/showthread.php?p=5480156

Revision history for this message
BigBoy_PDB (bigboy-pdb) wrote :

This is a confirmation about the problem.

It happened for me as well. The problem is identical to that mentioned in the post on Ubuntu Forums.

To reiterate, javascript files ending in '.js' are detected as C source code files. The mime type in nautilus is 'application/javascript' and in gedit it is 'C source code (text/x-csrc)'.

The beginning of the file starts with a comment of the form '/* ... */' and a line of the form 'function f(var) {'. Removing the comments causes the mime type to change to 'MATLAB script/function (text/x-matlab)'.

Revision history for this message
BigBoy_PDB (bigboy-pdb) wrote :

Sorry, I forgot to mention that I'm using Ubuntu 8.04

Changed in shared-mime:
importance: Unknown → Medium
Changed in shared-mime:
importance: Medium → Unknown
Changed in shared-mime:
importance: Unknown → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.