• 0

[Java] How to suppress Fatal Errors in the log


Question

Hi everyone,

I have a Java program that does some XML manipulation. It throws this error in my log:

[Fatal Error] :-1:-1: Premature end of file.

It is not causing any problems and it is beyond my control to fix it. Is there any way I can suppress these errors and clean up my log? Or maybe, change the message to be more friendly?

Thanks for any help. :)

Recommended Posts

  • 0
  azcodemonkey said:
I think you're confusing "classes" for "objects", and statics belong to the class, not an instance of a class. The class loader initializes a class when a static member is invoked, assigned or accessed. Classes are unloaded when the execution of the program ends, with some exceptions.

http://java.sun.com/docs/books/jls/third_e.../execution.html

My guess is that Class members, a.k.a. statics, are put on the stack and not on the heap, but I have yet to see any documentation that says one way or the other. It could be totally VM dependent.

It doesn't call any constructor. Class initialization is not equal to class construction.

First of you are confusing class objects with instances of class objects. Two different things.

Sorry you're just wrong. If you read some more bits of the link you posted. i.e http://java.sun.com/docs/books/jls/third_e...ions.html#41147

  Quote
15.9.3 Choosing the Constructor and its Arguments

Let C be the class type being instantiated. To create an instance of C, i, a constructor of C is chosen at compile-time by the following rules:

* First, the actual arguments to the constructor invocation are determined.

o If C is an anonymous class, and the direct superclass of C, S, is an inner class, then:

+ If the S is a local class and S occurs in a static context, then the arguments in the argument list, if any, are the arguments to the constructor, in the order they appear in the expression.

+ Otherwise, the immediately enclosing instance of i with respect to S is the first argument to the constructor, followed by the arguments in the argument list of the class instance creation expression, if any, in the order they appear in the expression.

Just because you don't write a constructor does not mean that object does not have one and just because you do not call a constructor does not mean one is not called.

Also you seem to be saying that a class object (or any other kind of object) may be initialised and used without being instantiated. How would this work?

  azcodemonkey said:
It is possible to code in Java without using objects.

Please provide a code example of this.

  • 0
  monkey13 said:
... you seem to be saying that a class object (or any other kind of object) may be initialised and used without being instantiated. ... Please provide a code example of this.

public class NoObjects {

	static { 
		// static initialiser - called when class is initialised
		System.out.println("Thes has been initialised");
	}

	public NoObjects() {
		// default constructor - called when an instance is created
		System.out.println("Aer of the class has been instantiated");
	}

	public static void main(String[] args) {
		// static method - called when app is run
		System.out.println("Hellod");
	}

}

  • 0

As I don't have Java here at work I can't check this but I assume you are making this point because the output is:

"The class has been initialised"

"Hello World"

and you're hoping this proves you're argument. However if you see this from the above link.

  Quote
15.9.5.1 Anonymous Constructors

An anonymous class cannot have an explicitly declared constructor. Instead, the compiler must automatically provide an anonymous constructor for the anonymous class. The form of the anonymous constructor of an anonymous class C with direct superclass S is as follows:

The class NoObjects is instantiated anonymously by the compiler because you did not instantiate it. Therefore it can not call the constructor you specified because it is not allowed to. This is not proof that it is not instantiated.

The whole program in this example is an anonymous instantiation of the class NoObjects

  • 0

It's anonymous because you did not instantiate it. It is not a class with no name. It can have a declared constructor on line 8 but this just isn't used in this anonymous instantiation of it.

It's anonymous to you. The JVM will still have all the stuff to do with an instance for that class it just doesn't let you at it.

  • 0

Yes it's not an anonymous class but it is an anonymous incident of that class. That is why I'm using the anonymous class stuff to show what happens with the case we are talking about.

Ok we'll look at it another way. If the class NoObjects is only initialised and not instantiated how does it get any memory? http://java.sun.com/docs/books/jls/third_e.../execution.html

  Quote
12.4.1 When Initialization Occurs

Initialization of a class consists of executing its static initializers and the initializers for static fields declared in the class. Initialization of an interface consists of executing the initializers for fields declared in the interface.

.....

12.5 Creation of New Class Instances

...

Whenever a new class instance is created, memory space is allocated for it with room for all the instance variables declared in the class type and all the instance variables declared in each superclass of the class type, including all the instance variables that may be hidden

....

You can not have any Java code without an object. The very class the code is in is an object its self at runtime.

Edited by monkey13
  • 0
  monkey13 said:
First of you are confusing class objects with instances of class objects. Two different things.

Sorry you're just wrong. If you read some more bits of the link you posted. i.e http://java.sun.com/docs/books/jls/third_e...ions.html#41147

Just because you don't write a constructor does not mean that object does not have one and just because you do not call a constructor does not mean one is not called.

Also you seem to be saying that a class object (or any other kind of object) may be initialised and used without being instantiated. How would this work?

Please provide a code example of this.

We're talking about statics, aren't we? We're talking about how statics are initialized, not objects. Objects are instantiations of classes. Statics are initialized when they are first accessed as the class is then loaded and its statics initialized. Again, class initialization is not equal to class instance construction.

As far as actual instances of a class are concerned, your reference is correct. In the context of discussing how statics work, it is not even relevant, nor is the anonymous class/constructors. Statics have nothing what so ever to do with class construction. The VM allocates memory for the class it is loading, not sure if it's stack(I'd assume so) or heap, and the data/functions remain in memory until program end, or in some special circumstances when the class is unloaded during normal execution. Think of statics as functions or static data in a C-library. You'd link to or load the lib and reference the functions without instantiating anything. The functions or static data just exists in memory until your unload the lib. This is analogous to how statics work in managed languages. C# uses the same semantics as Java does when it comes to statics.

http://msdn.microsoft.com/en-us/library/79b3xss3.aspx

note: Java doesn't have static classes, so there are nothing but non-static classes in that context

  Quote
A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.

http://msdn.microsoft.com/en-us/library/98f28cdx(VS.71).aspx

http://java.sun.com/docs/books/jls/third_e...es.html#8.3.1.1

  Quote
If a field is declared static, there exists exactly one incarnation of the field, no matter how many instances (possibly zero) of the class may eventually be created. A static field, sometimes called a class variable, is incarnated when the class is initialized (?12.4).

http://java.sun.com/docs/books/jls/third_e...es.html#8.4.3.2

  Quote
A method that is declared static is called a class method.Aclass> method is always invoked without reference to a particular object.> An attempt to reference the current object using the keyword this or the keyword super or to reference the type parameters of any surrounding declaration in the body of a class method results in a compile-time error. It is a compile-time error for a static method to be declared abstract.

A method that is not declared static is called aninstance> method>, and sometimes called a non-static method.An instance method is always invoked with respect to anobject>>, which becomes the current object to which the keywords this and super refer during execution of the method body.

I'm also well aware of default constructors being provided by the compiler should one not be provided explicitly, whether an anonymous class or not. Again, not relevant to statics.

I could write an example of not leveraging objects in Java, but I think you'd argue that I'm using objects because all my statics reside in a class. I can write procedurally in Java using 1 class for entry point and nothing but static methods that are completely stateless and do not leverage encapsulation, inheritance, or polymorphism.

  • 0
  monkey13 said:
Ok we'll look at it another way. If the class NoObjects is only initialised and not instantiated how does it get any memory?

Memory for the code of all the methods is allocated by the class loader when the class is loaded. Memory for the static variables is allocated when the class is initialised. It's only the memory for the instance variables that is allocated when an instance of the class is created. Since static methods are not allowed to reference instance variables they can (and do) execute without any instance of the class being created.

  • 0

Ok azcodemonkey good links and references. I'm afraid I'm going to ignore the C# MS stuff. I don't know anyhting about how C# works so I can't comment on that, but I do doubt it's exactly the same as Java.

Reading from that you seem to be saying that there are operations that can occur outside of an object. This is not so. Yes a static field can exist outside of an object an initialisation time, but how do you do anything with this static field without instantiating an object?

Yes a class method is invoked without a specific object method but that does not mean that an object does not exist and one is not created by the JVM to perform the operation.

You're thinking that because it says don't specify an object one doesn't exist. What I'm saying is you don't need to because Java does it for you and you'd just be confusing it by specifying one.

  Quote
I could write an example of not leveraging objects in Java, but I think you'd argue that I'm using objects because all my statics reside in a class. I can write procedurally in Java using 1 class for entry point and nothing but static methods that are completely stateless and do not leverage encapsulation, inheritance, or polymorphism.

Quite right. The whole thing would be one big class, therefore one big object at run time. Also because a class is of type object you would be doing both polymorphism and inheritance. Although you would fail on the encapsulation. ;)

  • 0
  JamesCherrill said:
Memory for the code of all the methods is allocated by the class loader when the class is loaded. Memory for the static variables is allocated when the class is initialised. It's only the memory for the instance variables that is allocated when an instance of the class is created. Since static methods are not allowed to reference instance variables they can (and do) execute without any instance of the class being created.

Yes but when is the memory to perform these operations allocated if no objects exist. Certain things can exist independently of objects but nothing can be done with them without an object. Again just because you don't specificaly create or need to create an object does not mean one is not created.

  • 0
  monkey13 said:
Yes but when is the memory to perform these operations allocated if no objects exist.

Everything needed to execute the static method is already in memory (as explained previously) once the class has been loaded and initialised (apart from variables local to the static method, which are created on the stack as required).

  • 0
  monkey13 said:
Certain things can exist independently of objects but nothing can be done with them without an object. Again just because you don't specificaly create or need to create an object does not mean one is not created.

OK, I think I may have an idea as to where your confusion arises. Yes, you are right, classes are Objects (instances of class Class) (note capitalisation!). However, unlike instances of any other class,

  Quote
Class objects are constructed automatically by the Java Virtual Machine as classes are loaded

(http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html).

So there is an Object, it's an instance of class Class, it has been instantiated, and all that happens before it can execute any of its static methods. This must not be confused with creating instances of the class - this can only be done (not by the class loader!) by executing a "new" statement which, in turn, invokes any default or explicit constructors.

  • 0
  JamesCherrill said:
OK, I think I may have an idea as to where your confusion arises. Yes, you are right, classes are Objects (instances of class Class) (note capitalisation!). However, unlike instances of any other class,

(http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html).

So there is an Object, it's an instance of class Class, it has been instantiated, and all that happens before it can execute any of its static methods. This must not be confused with creating instances of the class - this can only be done (not by the class loader!) by executing a "new" statement which, in turn, invokes any default or explicit constructors.

Well done you have said what I've been saying all along. It is not my confusion but yours as you didn't understand what was happening and how Java works.

I've been saying that classes are instantiated without a user doing it all the way through this thread only now you announce it like you've made some major breakthrough. Although you can still have instances of a class without using new. If you think about it there is a very obvious one.

Also to go from "Objects are not instantiated at all in my code I provided" to "Yes they are but now I'm going to argue about the semantics of this o(O)bject" looks a bit desperate.

  • 0

I see what you did there. You went from arguing that static methods are constructors(the statement that started this whole discussion for me), which they are not, to how the JVM creates objects behind the scenes to allow invocation. Invoking a static does indeed cause the JVM to do something, constructing classes to create a layout of the static's class, but the static invocation in and of itself does not create an instance of its containing type, which is the very definition of a constructor.

You were mixing language and causing confusion which is what I have a problem with. A student that puts on his paper that a static method is a constructor is going to get that statement marked as incorrect, and that is fact. And you also are equating object creation behind the scenes to object oriented development. They are not the same. Using statics is not using object oriented practices. Objects model behavior, statics do not. So I am totally correct that I can write a non-object oriented application in Java by using statics. I would not using objects despite what the framework may do to make it work. A class without non-static members is not a class that is going to be usable as an object. It is solely a container for functions. Sure, I'll be able to call toString on it, and treat it as an Object, but if it has no behavior, it isn't an object oriented application.

class A{

	public static void Foo(){ // ... do something }

}

class Main{

	public static void main(String[] args){
		A.Foo(); // this does not create an instance of A, which is what a constructor does.
		A _a = new A(); // this is an instance created with the default constructor provided at compile time
	}
}

  • 0

I didn't say that static methods are constructors. I said that object could be constructed by calling static methods. Once again (for about the 20th time) if I call a static method of a class that has not been specificity instantiated how does Java do this? Java cannot do anything without creating instances of objects. Just because you don't specify what is being created doesn't mean nothing is being created.

  azcodemonkey said:
And you also are equating object creation behind the scenes to object oriented development. They are not the same. Using statics is not using object oriented practices. Objects model behavior, statics do not. So I am totally correct that I can write a non-object oriented application in Java by using statics. I would not using objects despite what the framework may do to make it work. A class without non-static members is not a class that is going to be usable as an object. It is solely a container for functions. Sure, I'll be able to call toString on it, and treat it as an Object, but if it has no behavior, it isn't an object oriented application.

class A{

	public static void Foo(){ // ... do something }

}

class Main{

	public static void main(String[] args){
		A.Foo(); // this does not create an instance of A, which is what a constructor does.
		A _a = new A(); // this is an instance created with the default constructor provided at compile time
	}
}

Sorry you would not be using objects so therefore this is not object orientated? How you write your code changes the underling principals of how Java operates and invalidates it as an object orientated programming language?

Point 1. There is at least one object involved in this code before you even add any lines after class Main{ (see JamesCherrill)

Point 2 Again Just because you don't specify instantiation does not mean it doesn't happen. If A.Foo(); doesn't instantiate class A (or A is not already instantiated) how is this operation performed?

Point 3 (backs up point 2) There is one very major and obvious class, if you think about it, that is regularly instantiated without the use of new. What is it? (I've asked this question before and no-one has yet to answer it)

  • 0
  monkey13 said:
Point 1. There is at least one object involved in this code before you even add any lines after class Main{ (see JamesCherrill)

Please don't try to quote me in support of your bizarre ideas about object creation. The post you referred to was an attempt to understand why you were going wrong and maybe offer you a lifeline to dig yourself out of the increasingly deep hole into which you are digging yourself. No instance of the class is needed or created when a static method in that class is called.

Your fundamental error is in believing that

  Quote
Java cannot do anything without creating instances of objects.

This is simply not true.

  • 0
  JamesCherrill said:
No instance of the class is needed or created when a static method in that class is called.

Your fundamental error is in believing that

  Quote
Java cannot do anything without creating instances of objects.

This is simply not true.

Oh dear I'd assumed you had worked it out. Ok once again then. The question no-one seems to be able to answer. If Java does not create any objects how does it perform operations?

Also. Why does how you are writing the code completely invalidate it as an object orientated language?

  • 0
  monkey13 said:
<insult snipped>. Ok once again then. The question no-one seems to be able to answer. If Java does not create any objects how does it perform operations?

Also. Why does how you are writing the code completely invalidate it as an object orientated language?

1. Why do you think it needs an object to perform operations? It doesn't. That's why there is no answer to the question as asked.

2. Yes, you can write a Java progam with no objects instantiated. and that is not OO practice. The fact that it's possible in Java doesn't invalidate anything.

3. Just as a matter of curiosity - do you work as a software developer and, if so, in what language(s)?

  • 0

1. Yes it does because it is a pure object orientated language. Unlike C++ which is a language with object orientated features. I wonder if this is where the confusion arises in C++ it is possible to write non-OO stuff.

2. See above. The main class you use is an object at runtime.

3. Not exactly. I work in research at the moment which at the moment is mainly Matlab and a bit of C++. However I am the only one with an IT background at my work so that means I end up fielding all kinds of questions.

Edit: Perhaps this will clear it up.

http://java.sun.com/docs/books/tutorial/ja...epts/class.html

Bit basic I know but it makes this rather succinct point.

  Quote
A class is the blueprint from which individual objects are created.

If you have the blueprints to a house can you live in it? No, because you need to build the house before you can do anything with it.

Edited by monkey13
  • 0

I find this difficult to express but you are obviously an intelligent and articulate person. Your misunderstandings about Java are natural, given that you don't actually work with the language. There are a number of people who post regularly in these forums who have huge experience in Java, all of whom are willing to help you if you are willing to listen. I personally have only been a software developer for 30 years, and using Java exclusively since 1996, but I still learn a lot from those contributors who know more than I do. I guess you're too far down the road of rejection to listen to anything I have to say, but maybe you can open your mind to people like azcodemonkey and alexanderkl and kane81. They really do know what they're talking about. Good luck, and goodbye.

James

  • 0

You're right I don't work with the language now. As I said it's been a few years since I worked Java.

For all your years of expertise you couldn't correctly identify or solve the problem with Annorax's (the original poster) code. Whist I was offering solutions you were harping on about needing the "ACTUAL CODE" as you put it and then the solution you offered, sub classing the Java platform to avoid the error rather than dealing with it. Is, IMHO, very bad practice. If that is being

  JamesCherrill said:
too far down the road of rejection to listen to anything I have to say

I'm very happy here. ;)

Take care.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • let's be honest here, it was in the line of secret doxing app
    • Dating safety app Tea spills private chats in new leak by Usama Jawad Tea is (was?) an extremely popular "dating safety" app designed for women who typically uploaded pictures of men they have dated, recounting their experience, and highlighting red flags. The app maintains exclusivity to women by requiring all its users to submit a selfie and government identification during the sign-up process. It was the target of a major breach a couple of days ago due to a Firebase bucket being left publicly exposed, leaking the identification data and other sensitive information for thousands of users. Now, the app has been struck with a second cybersecurity incident and it is arguably bigger than the first. 404 Media reports that a second database has leaked and it contains about 1.1 million chat messages discussing some sensitive topics that people likely wouldn't want to make public. These include topics like cheating partners, abortions, and unfaithful boyfriends. The messages span from 2023 to last week, but the impact and scope of the leak is unclear. The person who did discover the database noted that practically any user could access the repository using their own API key. In a statement to Bleeping Computer, Tea has confirmed the second breach too, noting that "some" direct messages (DMs) have been exposed. The company has decommissioned the affected system for now, but claims that other infrastructure remains unaffected. It has emphasized that it will invest efforts in the coming days to improve its cybersecurity posture, but did not share any further details at this time. The service will also be reaching out to its affected customers and offer them free identity protection services as a sort of an apology. These cybersecurity incidents further highlight the need to be vigilant when sharing identifiable information online, especially with apps which are very new to the market and have not yet matured. Security researchers and analysts have cautioned the public that it is very possible to locate social media profiles of Tea users due to all the data that has been leaked.
    • 26200.5722 is the first available 25H2 build from the ge_release_svc_betaflt branch (25H2's previous branch was the "ge_prerelease_im" branch). The 26200.5722 release also removes the "Insider Preview" references in the system area. These significant changes usually indicates that the public release of 25H2 will be ready within 6 weeks to 2 months.
    • Microsoft: Windows Autopatch is the safest way to upgrade enterprise PCs to Windows 11 by Usama Jawad A few hours ago, Microsoft published a guide for IT admins explaining how they can use Intune to upgrade Windows 10 devices to Windows 11, while also migrating from Active Directory (AD) to a cloud-native system like Entra ID. The company has also published a similar guide, but switched the tool to Windows Autopatch, claiming that it is the fastest and safest way for enterprise PCs to update to Windows 11. For those unaware, Windows Autopatch is a way to automate updates while empowering IT admins to ensure that endpoints are healthy and compliant through ring-based, staggered deployments. IT admins also have the ability to reverse updates easily if something does go wrong. In the current scenario of upgrading enterprise PCs to Windows 11 using Autopatch, Microsoft has outlined a four-step process. The first involves assessing Windows 11-readiness across your organization, assigning Entra ID groups to devices, and then mapping these groups to rollout rings in Autopatch. Next, IT admins should segment devices into Windows Autopatch groups, while also defining staggered rollout policies controlled through rollout rings. At a base level, there should be two groups: devices that meet the criteria of Windows 11 and should upgrade to it, and Windows 10 hardware that doesn't meet the criteria and should receive Extended Security Updates (ESUs). Devices should be spread in a logical manner across various rings, with each group having a dedicated update policy. The third step involves defining the speed of staggered update rollouts. This can be managed through the Intune admin center, which gives you control over sequencing, pace, and deferrals. Finally, IT admins should monitor the rollout of the Windows 11 update through the Windows Autopatch feature update reporting module. It contains the update status across devices, trendlines within historical views, and remediation guidance for errors. Microsoft believes that this combination of Windows Autopatch groups and Intune is the best way to upgrade to Windows 11, so IT admins should get started right away as support for Windows 10 is ending on October 14, 2025.
    • TDP of this CPU is 60 watts higher than Ryzen 7600. At s usage rate of four hours per day, at a cost of twelve cents per KWh, the Intel cost $10.51 more per year to use. I don't see a real advantage to Intel here.
  • Recent Achievements

    • Dedicated
      ataho31016 earned a badge
      Dedicated
    • First Post
      Gladiattore earned a badge
      First Post
    • Reacting Well
      Gladiattore earned a badge
      Reacting Well
    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      652
    2. 2
      ATLien_0
      261
    3. 3
      Xenon
      165
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      107
  • Tell a friend

    Love Neowin? Tell a friend!